我正在试着/除了这里:
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"
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()还是不能让它起作用。
发布于 2020-07-21 17:08:36
您可以尝试下面的解决方案以避免同步错误。
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.messagehttps://stackoverflow.com/questions/63019233
复制相似问题