【问题标题】:How to fix NoSuchElementException Python error on clicking on webpage button?单击网页按钮时如何修复 NoSuchElementException Python 错误?
【发布时间】:2019-10-29 15:27:12
【问题描述】:

基本上我需要点击一个按钮,该按钮位于网页的框架内。我试过了:

1) 切换到框架,效果很好,不返回任何错误:

driver.switch_to.frame(driver.find_element_by_css_selector('#iframe'))

3) 添加 20 秒的时间延迟,这不会改变结果,因为它最终只是超时:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "dx-button"))).click()

我相信 CSS 元素的名称是正确的,因为我使用开发者模式 -> 复制选择器复制了它。

为了让 selenium 找到这个 CSS 元素,我还能做些什么吗?

添加延时前的错误:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"dx-button"}

添加延时后报错:

selenium.common.exceptions.TimeoutException: Message: 

谢谢。

【问题讨论】:

标签: python css selenium webdriver frame


【解决方案1】:

可能会检查切换的 iframe 是否是具有按钮的准确 iframe。

如果正确,你能用 XPATH 定位器试试同一行吗?

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@class, 'button')]"))).click()

【讨论】:

    猜你喜欢
    • 2019-08-29
    • 1970-01-01
    • 2016-04-02
    • 1970-01-01
    • 1970-01-01
    • 2016-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多