13

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.

4
  • 1
    xpath is never a good thing to use with selenium. Try searching strictly by id since you have it Commented Aug 24, 2013 at 17:42
  • The code works for me..could you test the same code but using chrome instead of firefox? Commented Aug 24, 2013 at 18:02
  • You could try downgrading firefox. I've read that new versions of firefox often break Selenium interactions. Commented Aug 24, 2013 at 18:41
  • the thing is that my work uses firefox and im trying to learn selenium for it. I'm trying to use xpath because the Web App that I will be testing doesn't have IDs for the elements that I need to click... Commented Aug 24, 2013 at 19:01

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm, strange... Try it: firefox.click("xpath=//a[@id='gb_23']")
1

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

Comments

0

Try

from selenium.webdriver.common.action_chains import ActionChains

ActionChains(driver).move_to_element(button).click(button_sub).perform()

You can also use ClickElement.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.