Selenium python click on element nothing happens

I am trying to click the Gmail link on the Google homepage in Selenium using WebDriver in Python. My code basically repeats the one found here: Why can't I select an element in selenium?

My code is:

import selenium.webdriver as webdriver firefox = webdriver.Firefox() firefox.get("http://www.google.ca") element = firefox.find_element_by_xpath(".//a[@id='gb_23']") element.click() 

Webdriver loads the page and then nothing happens. I tried using ActionChains and move_to_element (element), click (element) and then execute (), but nothing happens.

+4
source share
2 answers

Use the find_element_by_id method:

 element = firefox.find_element_by_id("gb_23") element.click() 

or fix your xpath for:

 "//a[@id='gb_23']" 

Here you have a good tutorial.

+5
source

try this because i dont see this id in html:

 driver = webdriver.Firefox() driver.get("http://www.google.ca") element = driver.find_element_by_link_text("Gmail") element.click() 
0
source

Source: https://habr.com/ru/post/1498746/


All Articles