首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium:尝试/除- driver.driver.find_element_by_xpath().click -不能传递

Selenium:尝试/除- driver.driver.find_element_by_xpath().click -不能传递
EN

Stack Overflow用户
提问于 2020-07-21 16:49:02
回答 1查看 276关注 0票数 0

我正在试着/除了这里:

代码语言:javascript
复制
try:
    driver.find_element_by_xpath("/html/body/div[5]/div/div[1]/div[2]/div/div/article/table/tbody/tr[10]/td/a").click()
except NoSuchElementException:
    driver.find_element_by_xpath("/html/body/div[5]/div/div[1]/div[2]/div/div/article/table/tbody/tr[11]/td/a").click()

我总是得到: selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{“方法”:“xpath”,"selector":"/html/body/div5/div/div1/div2/div/div/article/table/tbody/tr10/td/span1"}

备注:

tried:"try/except"

  • I已经尝试过:“除了NoSuchElementException"

  • "from selenium.common.exceptions导入NoSuchElementException"

  • I已尝试:

代码语言:javascript
复制
try:
    test = driver.find_element_by_xpath("/html/body/div[5]/div/div[1]/div[2]/div/div/article/table/tbody/tr[10]/td/a")
    test_click = test.click()
except NoSuchElementException:
    driver.find_element_by_xpath("/html/body/div[5]/div/div[1]/div[2]/div/div/article/table/tbody/tr[11]/td/a").click()

还是不能让它起作用。

EN

回答 1

Stack Overflow用户

发布于 2020-07-21 17:08:36

您可以尝试下面的解决方案以避免同步错误。

代码语言:javascript
复制
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By

try:
    element = WebDriverWait(driver, 20).until(
          EC.presence_of_element_located((By.XPATH, your element )))
except TimeoutException as ex:
            print ex.message
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63019233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档