【发布时间】:2018-12-31 14:05:51
【问题描述】:
我正在尝试使用 selenium 框架来了解有关 Web 浏览器自动化的知识。因此,我决定打造一款奥迪车型……
到目前为止我的代码:
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
chrome_driver = webdriver.Chrome(executable_path=r"chromedriver_win32\chromedriver.exe")
chrome_driver.get("https://www.audi.de/de/brand/de/neuwagen.html")
# choose A3 model
chrome_driver.find_element_by_xpath('//*[@id="list"]/div[1]/ul/li[2]/a[2]').click()
# choose sedan version
WebDriverWait(chrome_driver, 3).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="a3limo"]/div/a'))).click()
# start model configuration
WebDriverWait(chrome_driver, 3).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[1]/div[2]/div/div[6]/div[2]/div/div[1]/ul/li[1]/a'))).click()
# choose the s-line competition package
WebDriverWait(chrome_driver, 3).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[1]/div[2]/div/div[7]/div[2]/div[2]/div[3]/div[1]/div/div[1]/div/div[1]/span/span'))).click()
# accept the s-line competition package
WebDriverWait(chrome_driver, 3).until(EC.visibility_of_element_located((By.XPATH, '/html/body/div[5]/div/div/div/div/div/ul[2]/li[2]/a'))).click()
现在,代码在start model configuration 行上已经失败(请参阅网页https://www.audi.de/de/brand/de/neuwagen/a3/a3-limousine-2019.html 上的“配置启动”按钮)。 xPath 必须是正确的,并且元素也应该是可见的,那么我在这里做错了什么?
【问题讨论】:
-
请发布您遇到的异常
-
我收到超时异常:raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
标签: python selenium selenium-webdriver web-scraping