WebDriverWait无法等待该URL,等待标记信息如下:
class="iw_component" id="c1417094965155"
从以下代码中提示错误消息"selenium.common.exceptions.TimeoutException: "
:
from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
display=Display(visible=0,size=(800,800))
display.start()
driver = webdriver.Firefox()
driver.get("url")
try:
element = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CLASS_NAME, "iw_component"))
)
finally:
driver.quit()
display.stop()
答案 0 :(得分:1)
您所关注的元素位于<iframe>
标记内,id="sysdata_iframe"
。首先,您必须使用driver.switch_to.frame()
切换到该框架。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("url")
driver.switch_to.frame('sysdata_iframe')
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'iw_component')))
driver.quit()