Aaron Lam
Aaron Lam

Reputation: 387

selenium python click on element nothing happens

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

Answers (3)

A McGuinness
A McGuinness

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

user7365070
user7365070

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

swietyy
swietyy

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']"

Here you have nice tutorial.

Upvotes: 11

Related Questions