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
  1. import undetected_chromedriver.v2 as uc
  2. from selenium.webdriver.chrome.options import Options
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.support import expected_conditions as EC
  5. from selenium.webdriver.support.wait import WebDriverWait
  6. import time


  7. #coinlist 自动登入插件
  8. def get_exe(driver,username,password,secret):
  9.     driver.get('chrome-extension://bjggdloikijmgdhnlaiaeobomoddjcbe/popup.html')
  10.     driver.find_element(By.NAME,"username").send_keys(username)
  11.     driver.find_element(By.NAME,'password').send_keys(password)
  12.     driver.find_element(By.NAME,'key').send_keys(secret)
  13.     driver.find_element(By.XPATH,'//div[@class="confirm"]').click()
  14.     time.sleep(1000)
  15. def iscaptcha(driver):
  16.     pass


  17. def get_ext(driver,ele):
  18.     js = 'return {}.querySelector("extensions-item").shadowRoot'.format(ele)
  19.     js = '''
  20.    
  21.     for (var i=0;i<ele.length;i++)
  22. {
  23.     document.write(cars[i] + "<br>");
  24. }
  25.     '''
  26.     return driver.execute_script(js)
  27. def get_id(driver):
  28.     driver.get('chrome://extensions/')
  29.     shadowrootlist = get_shadow(driver)
  30.     print(shadowrootlist)
  31.     for shadow in shadowrootlist:
  32.         # p = get_ext(driver,shadow)
  33.         # print(p)
  34.         print(shadow)  #可以正常输出一个WebElement对象
  35.         s1 = shadow.find_elemet(By.XPATH,'//extensions-item')  #报错
  36.         p= get_ext(driver,s1)
  37.         print(p)
  38.     #     div = get_ext(driver,shadow)
  39.     #     print(div)
  40.     # print(lis)
  41. def get_shadow(driver):
  42.     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')")
  43.     # shadow_root = driver.execute_script("return document.querySelector('extensions-manager').shadowRoot.querySelector('cr-view-manager').querySelector('extensions-item-list').shadowRoot.querySelector('.items-container')")
  44.     return shadow_root
  45. if __name__ == '__main__':
  46.     options = Options()
  47.     options.add_argument("--user-data-dir=" + r"C:/Users/Administrator/AppData/Local/Google/Chrome/User Data/")
  48.     driver = uc.Chrome(options, version_main=96)
  49.     username = 'pierrelattimer53@gmail.com'
  50.     password = 'asyufguia646'
  51.     secret = '7vqx4dzbp35un7xllg6mm7dy'
  52.     # get_exe(driver,username,password,secret)
  53.     # from selenium import webdriver
  54.     # driver = webdriver.Chrome(chrome_options=options)
  55.     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