51Testing软件测试论坛
标题:
'WebElement' object has no attribute 'find_elemet'
[打印本页]
作者:
测试积点老人
时间:
2022-1-18 13:18
标题:
'WebElement' object has no attribute 'find_elemet'
还有一个就是driver执行一个js脚本,进入到iframe也是出错,这个进入iframe因为代码原因无法使用switch
import undetected_chromedriver.v2 as uc
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time
#coinlist 自动登入插件
def get_exe(driver,username,password,secret):
driver.get('chrome-extension://bjggdloikijmgdhnlaiaeobomoddjcbe/popup.html')
driver.find_element(By.NAME,"username").send_keys(username)
driver.find_element(By.NAME,'password').send_keys(password)
driver.find_element(By.NAME,'key').send_keys(secret)
driver.find_element(By.XPATH,'//div[@class="confirm"]').click()
time.sleep(1000)
def iscaptcha(driver):
pass
def get_ext(driver,ele):
js = 'return {}.querySelector("extensions-item").shadowRoot'.format(ele)
js = '''
for (var i=0;i<ele.length;i++)
{
document.write(cars[i] + "<br>");
}
'''
return driver.execute_script(js)
def get_id(driver):
driver.get('chrome://extensions/')
shadowrootlist = get_shadow(driver)
print(shadowrootlist)
for shadow in shadowrootlist:
# p = get_ext(driver,shadow)
# print(p)
print(shadow) #可以正常输出一个WebElement对象
s1 = shadow.find_elemet(By.XPATH,'//extensions-item') #报错
p= get_ext(driver,s1)
print(p)
# div = get_ext(driver,shadow)
# print(div)
# print(lis)
def get_shadow(driver):
shadow_root = driver.execute_script("return document.querySelector('extensions-manager').shadowRoot.querySelector('cr-view-manager').querySelector('extensions-item-list').shadowRoot.querySelector('#container').querySelectorAll('extensions-item')")
# shadow_root = driver.execute_script("return document.querySelector('extensions-manager').shadowRoot.querySelector('cr-view-manager').querySelector('extensions-item-list').shadowRoot.querySelector('.items-container')")
return shadow_root
if __name__ == '__main__':
options = Options()
options.add_argument("--user-data-dir=" + r"C:/Users/Administrator/AppData/Local/Google/Chrome/User Data/")
driver = uc.Chrome(options, version_main=96)
username = 'pierrelattimer53@gmail.com'
password = 'asyufguia646'
secret = '7vqx4dzbp35un7xllg6mm7dy'
# get_exe(driver,username,password,secret)
# from selenium import webdriver
# driver = webdriver.Chrome(chrome_options=options)
get_id(driver)
复制代码
[attach]136187[/attach]
作者:
qqq911
时间:
2022-1-19 12:30
可以切换fream吧
作者:
郭小贱
时间:
2022-1-19 14:20
要先切换到iframe内再进行下一步操作的.
作者:
jingzizx
时间:
2022-1-19 17:36
没定位到把
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2