selenium.common.exceptions.TimeoutException while invoking .click() on an element through expected_conditions

☆樱花仙子☆ 提交于 2021-02-13 05:43:47

问题


Using python, chromedriver and Windows. I've working on a script for some months which uses .click() function regularly, few days ago it stopped working anywhere on the site. I've been trying to locate the element by id, xpath, etc... or even click it by send_keys(Keys.ENTER) with no success. I'm just trying to click the login icon but nothing happens. Seems to find the element and even click it, but nothing happens. This is the site and here the code:

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()

a part from not working this is what I get from the terminal:

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:

and this is what should happen on the browser:

-first click on the icon

-and after this should appear


回答1:


As per the url you have shared to click on the link with text as Regístrate o inicia sesión you can take help of either of the following Locator Strategies:

  • LINK_TEXT
  • PARTIAL_LINK_TEXT
  • CSS_SELECTOR
  • XPATH

Here is the sample code using 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()

Browser Snapshot:



来源:https://stackoverflow.com/questions/50843483/selenium-common-exceptions-timeoutexception-while-invoking-click-on-an-elemen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!