zoukankan      html  css  js  c++  java
  • 伪元素无法定位问题 NoSuchElementException: Message: no such element: Unable to locate element

    Selenium+Python 定位一个伪元素的时候总是无法定位,连绝对定位都试过了,还是不行。

    查了下可能是对应页面的元素还没加载完成,试着加了个显示等待时间,果然获取到了。

    from selenium import webdriver
    import time
    from selenium.webdriver.support.ui import WebDriverWait
    
    driver = webdriver.Chrome()
    driver.get('https://XXXX.com/login')
    
    driver.find_element_by_id('account').clear()
    driver.find_element_by_id('account').send_keys('13120922896')
    driver.find_element_by_id('password').clear()
    driver.find_element_by_id('password').send_keys('KMtLcEbjfM')
    driver.find_element_by_xpath('//button[@class="ant-btn src-pages-login-index-module__login-button--9qwKk ant-btn-primary"]').click()
    
    wait = WebDriverWait(driver,5,0.5)
    wait.until(lambda driver: driver.find_element_by_xpath('//div[@class="src-pages-login-index-module__shop-card--brzB-"]/button[@class="ant-btn src-pages-login-index-module__choose-btn--1x6QG ant-btn-primary"]'))
    driver.find_element_by_xpath('//div[@class="src-pages-login-index-module__shop-card--brzB-"]/button[@class="ant-btn src-pages-login-index-module__choose-btn--1x6QG ant-btn-primary"]').click()

    WebDriverWait(driver,timeout,poll_frequency=0.5,ignored_exceptions=None)

    timeout:最长超时时间,默认以秒为单位

    poll_frequency:检测的间隔时间,默认为0.5s

    ignored_exceptions:超时后的异常信息,默认情况下抛出NoSuchElementException异常

    until(method,message=''):调用该方法提供的驱动程序作为一个参数,直到返回值为True

  • 相关阅读:
    php上传进度条
    array_combine — 创建一个数组,用一个数组的值作为其键名,另一个数组的值作为其值
    password_hash 与 password_verify
    这是一个微信带参数的二维码,自定义菜单,与图文回复
    go to 语句用起来还是挺方便的
    初次使用海豚php的一个例子
    图片下载
    一对一的关联映射
    延迟加载
    proxy和proxy-no的策略取值区别
  • 原文地址:https://www.cnblogs.com/suancaipaofan/p/11799735.html
Copyright © 2011-2022 走看看