Categories
java javascript selenium selenium-webdriver

Selenium WebElement.click() vs. Javascript click event

I was wondering what the differences are between calling the click() method of the WebElement versus finding the element by id and firing the click event with JavaScript.

Just to be clear in the first method I call the .click() of an instance of WebElement:

myWebElement.click();

The second technique is:

((JavascriptExecutor)driver).executeScript("document.getElementById('myElementID').click()");

I’m interested in knowing all the differences between these two techniques for clicking web elements, and also advantages and disadvantages of each.