Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

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.

1 Answer

0 votes
by (62.9k points)

Try clicking the element through Action class.

WebElement webElement = driver.findElement(By.id("Your ID Here"));

Actions builder = new Actions(driver);

builder.moveToElement(webElement).click(webElement);

builder.perform();

You can also try clicking element by Javascript, If clicking with action class does not work,

WebElement webElement = driver.findElement(By.id("Your ID here"));

JavascriptExecutor executor = (JavascriptExecutor) driver;

executor.executeScript("arguments[0].click();", webElement);

Hope this helps!

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium course!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...