使用 python、chromedriver 和 Windows。
我花了几个月的时间编写一个定期使用 .click() 函数的脚本,几天前它在网站上的任何地方停止工作。我一直在尝试通过 id、xpath 等找到该元素...甚至通过 send_keys(Keys.ENTER)
单击它,但没有成功。我只是想单击登录图标,但没有任何反应。似乎找到了该元素,甚至单击它,但没有任何反应。这是the site这里是代码:
browser = webdriver.Chrome(chrome_options=options, executable_path=r'chromedriver.exe')
browser.get(('https://es.wallapop.com/'))
signInButton = WebDriverWait(browser, 5).until(EC.element_to_be_clickable((By.ID, 'js-show-login-modal')))
signInButton.click()
signInButton = WebDriverWait(browser, 5).until(EC.element_to_be_clickable((By.ID, 'btn-go-login-form')))
signInButton.click()
不工作的一部分是我从终端得到的:
Traceback (most recent call last):
File "wallapop_delete.py", line 55, in <module>
signInButton = WebDriverWait(browser, 5).until(EC.element_to_be_clickable((B
y.ID, 'btn-go-login-form')))
File "C:\Users\zaico\AppData\Local\Programs\Python\Python36\lib\site-packages\
selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
这就是浏览器上应该发生的情况:
最佳答案
根据您共享的网址,点击文本为Regístrate o inicia sesión的链接,您可以寻求以下任一帮助 Locator Strategies :
LINK_TEXT
PARTIAL_LINK_TEXT
CSS_SELECTOR
XPATH
以下是使用 PARTIAL_LINK_TEXT
的示例代码:
# -*- coding: UTF-8 -*-
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
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument('disable-infobars')
browser=webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
browser.get("https://es.wallapop.com/")
WebDriverWait(browser, 5).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, 'strate o inicia sesi'))).click()
浏览器快照:
关于python - 通过 Expected_conditions 在元素上调用 .click() 时,selenium.common.exceptions.TimeoutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50843483/