WebDriver click() vs JavaScript click()

0
0

The Story:

Here on StackOverflow, I’ve seen users reporting that they cannot click an element via selenium WebDriver “click” command and can workaround it with a JavaScript click by executing a script.

Example in Python:

element = driver.find_element_by_id("myid")
driver
.execute_script("arguments[0].click();", element)

Example in WebDriverJS/Protractor:

var elm = $("#myid");
browser
.executeScript("arguments[0].click();", elm.getWebElement());

The Question:

Why is clicking “via JavaScript” works when a regular WebDriver click does not? When exactly is this happening and what is the downside of this workaround (if any)?

I personally used this workaround without fully understanding why I have to do it and what problems it can lead to.

  • You must to post comments
Showing 0 results
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website