Reputation: 387
I am trying to click on the Gmail link on the Google frontpage in Selenium with the WebDriver on Python. My code basically replicates the one found here: Why Cant I Click an Element in Selenium?
My Code:
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()
The webdriver loads the page and then nothing happens. I've tried using the ActionChains and move_to_element(element), click(element), then perform() but nothing happens either.
Upvotes: 13
Views: 43597
Reputation: 88
Try
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(button).click(button_sub).perform()
You can also use ClickElement
.
Upvotes: 0
Reputation:
try this because i can't see this id in the html:
driver = webdriver.Firefox()
driver.get("http://www.google.ca")
element = driver.find_element_by_link_text("Gmail")
element.click()
Upvotes: 1
Reputation: 834
Use find_element_by_id
method:
element = firefox.find_element_by_id("gb_23")
element.click()
or correct your xpath to:
"//a[@id='gb_23']"
Upvotes: 11