user6651227 user6651227 - 1 month ago 15
Python Question

python selenium to click a link

since I updated my firefox to 49.02 and selenium to 3.0.1, my previous code to sign in to my

bing account
does not work.

there is a
Sign in
link in
www.bing.com
, I could successfully click this link by calling:

driver.get("http://www.bing.com")
driver.implicitly_wait(20)
driver.find_element_by_link_text('Sign in').click()


however, after the upgrade, I receive a strange error message which contains no message at all:

selenium.common.exceptions.ElementNotVisibleException: Message:


if I only call
driver.find_element_by_link_text('Sign in')
, I will receive no error message. This seems like selenium could successfully locate this link, but somehow it can not click this button.

I have also tried to locate
Sign in
by it
class name
or by clicking the icon instead, but all such efforts are useless.

I do not know if the error is caused by Microsoft to block automated logging in or the error in my code. Helps appreciated!

calling
driver.find_element_by_xpath('//a[span = "Sign in"]').click()
as suggested by
alecxe
still does not resolve the issue.

Answer

Wait for the link to be clickable:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
sign_in = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Sign in")))
sign_in.click()
Comments