【问题标题】:selenium.common.exceptions.TimeoutException while invoking .click() on an element through expected_conditionsselenium.common.exceptions.TimeoutException 同时通过 expected_conditions 在元素上调用 .click()
【发布时间】:2018-06-13 17:58:20
【问题描述】:

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

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

-首先点击图标

-之后应该会出现

【问题讨论】:

  • 您检查过(浏览器)错误吗?
  • 你的 chrome 和 chrome 驱动版本是什么
  • @Zaico- 没听懂,请加上chrome浏览器和chrome驱动的版本号
  • @Zaico 是的,我已经看到了这些屏幕,因为您的代码与我的旧 chromedriver(2.36?)一起使用了 try/except。我刚刚将我的 chromedriver 升级到最新版本(2.40?),您的代码无需任何修改即可运行。您是否尝试过升级您的 chromedriver?
  • @Zaico - 请将您的 chromedriver 更新到 2.40

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


【解决方案1】:

根据您分享的 url,点击带有文本为 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()

浏览器快照:

【讨论】:

  • 谢谢。问题是一旦我登录元素点击一次工作不再。例如,如果它托盘点击WebDriverWait(browser, 5).until(EC.element_to_be_clickable((By.XPATH, '/html/body/tsl-root/tsl-list/div/div/div/tsl-catalog-item[1]/div/div[2]/span[2]/span/button[4]'))).click() 没有任何反应,甚至没有错误
猜你喜欢
  • 2020-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-13
  • 1970-01-01
  • 2014-10-19
相关资源
最近更新 更多