我试图点击包含以下代码的按钮:
<div style="text-align:center" id="plus_res">
<img src="https://www.tunlancer.com/theme/images/plus_resv2.png" align="plus d'elements" title="plus d'elements" style="cursor:pointer" onclick="plus_resultat()">
</div>我试过:
image = driver.find_element_by_xpath("//img[contains(@src,'https://www.tunlancer.com/theme/images/plus_resv2.png')]")
driver.execute_script("arguments[0].click();", image)driver.find_element_by_id('plus_res').click()driver.find_element_by_xpath('//*[@id="plus_res"]/img').click()但它显示的是NoSuchElementException。我该怎么修呢?
发布于 2021-08-31 21:22:03
也许你得加点时间。
像这样的事情应该有效:
time.sleep(5)
driver.find_element_by_css_selector('img[src="https://www.tunlancer.com/theme/images/plus_resv2.png"]').click()发布于 2021-08-31 21:19:03
在访问该元素之前,我想您错过了一个延迟/等待。
请试试这个:
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.XPATH, '//img[@onclick="plus_resultat()"]'))).click()您将需要下列导入:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC此外,元素也可能在iframe中。
https://stackoverflow.com/questions/69005375
复制相似问题