python - 通过 Expected_conditions 在元素上调用 .click() 时,selenium.common.exceptions.TimeoutException

标签 python google-chrome selenium selenium-webdriver selenium-chromedriver

使用 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:

这就是浏览器上应该发生的情况:

-首先单击图标 enter image description here

- 之后应该出现 enter image description here

最佳答案

根据您共享的网址,点击文本为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()

浏览器快照:

strate o inicia sesi

关于python - 通过 Expected_conditions 在元素上调用 .click() 时,selenium.common.exceptions.TimeoutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50843483/

相关文章:

python - 使用 where 通过索引从 HDFStore 选择行

javascript - Selenium:我怎么能告诉 Selenium 等待按钮元素?

python - gnumpy中是否有hstack的实现

python - 你可以在 Django 中为模型表单使用表单向导吗?

css - Bootstrap 4 CSS 导致 Chrome 的打印 "Layout"消失

python - 使用 Selenium webdriver 单击 Google 搜索结果中的链接

java - 将字符串数组列表拆分为多个子字符串并将它们添加到 hashmap : JAva | Selenium

python - 如何使用预期条件 new_window_is_opened 切换选项卡并使用 Selenium 和 Python 验证页面标题

python进程批量列出元素

javascript - 如何删除一个重要的 CSS 属性?