我正在自动化网站以获取一些数据。我曾经在某个时候使用过显式/隐式等待,效果很好。但是当URL更改为另一个页面时..我猜它在加载其DOM时遇到问题,我找不到任何元素。 有什么办法可以找到元素
我尝试使用睡眠,将元素定位符更改为ID,CLASS,CSS SELECTOR,XPATH,TITLE等。 尝试将最大超时时间更改为30分钟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
import time
driver = webdriver.Chrome(r".\chromedriver")
driver.implicitly_wait(180)
driver.maximize_window()
driver.get("url")
elem_username = driver.find_element(By.CSS_SELECTOR, 'some_selector')
elem_username.clear()
elem_username.send_keys("user-name")
elem_pass = driver.find_element(By.CSS_SELECTOR, 'some_selector')
elem_pass.clear()
elem_pass.send_keys("pass-word")
elem_login = driver.find_element(By.CLASS_NAME, 'some-class').click()
#element = WebDriverWait(driver, 180).until(EC.presence_of_element_located((By.ID, "some-id")))
elem_click = driver.find_element(By.ID, "some-id").click()
t1 = time.asctime()
print(t1)
#unable to find below element after 30 min too
element = WebDriverWait(driver, 1800).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'some-selector')))
t2 = time.asctime()
print(t2)
elem_search = driver.find_element(By.CSS_SELECTOR, 'some-selector').click()
elem_transact = driver.find_element(By.CSS_SELECTOR, 'some-selector').click()
错误消息是超时异常:
回溯(最近通话最近): 文件“ file.py”,第24行,在 元素= WebDriverWait(驱动程序,1800)。直到(EC.presence_of_element_located((由CSS_SELECTOR, '某些选择器')) 文件“ C:\ Users \ tusmitta \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ selenium \ webdriver \ support \ wait.py”, 80行,直到 引发TimeoutException(消息,屏幕,堆栈跟踪) selenium.common.exceptions.TimeoutException:消息: