click command in selenium webdriver does not work

OrwellHindenberg picture OrwellHindenberg · Jul 26, 2012 · Viewed 130.9k times · Source

I have just recently done an export of my selenium IDE code to selenium web driver. I have found that a lot of the commands that worked in IDE either fail to work or selenium web driver claims to not support at all. So far I've been tackling these issues one at a time which is less than ideal...

Currently I'm working on finding out why clicking on a button does not work with web driver while it had previously worked in selenium IDE. My browser is FF 13 and my OS is Ubuntu.

Code Snippet

WebElement loginButton = driver.findElement(By.name("submit"));
loginButton.click();

I had previously tried

driver.findElement(By.name("submit")).click();

however the above line failed as well. The element is getting selected, however it does not log us in as I would like. I found other pages with similar problems, but their problem seemed to be with Internet Explorer not Firefox. I don't even want to think about the problems IE will give me down the road.

thanks,

P.S. A tip on a better way to migrate from selenium IDE to Selenium Webdriver without losing all the tests I've written could solve this issue as well.

Answer

TheLifeOfSteve picture TheLifeOfSteve · Jul 27, 2012

If you know for sure that the element is present, you could try this to simulate the click - if .Click() isn't working

driver.findElement(By.name("submit")).sendKeys(Keys.RETURN);

or

driver.findElement(By.name("submit")).sendKeys(Keys.ENTER);