👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
The Story:
Here on StackOverflow, I"ve seen users reporting that they cannot click an element via selenium WebDriver "click" command and can work around 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.
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from WebDriver click() vs JavaScript click(), check other code Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano WebDriver click() vs JavaScript click()
- Deutsch WebDriver click() vs JavaScript click()
- Français WebDriver click() vs JavaScript click()
- Español WebDriver click() vs JavaScript click()
- Türk WebDriver click() vs JavaScript click()
- Русский WebDriver click() vs JavaScript click()
- Português WebDriver click() vs JavaScript click()
- Polski WebDriver click() vs JavaScript click()
- Nederlandse WebDriver click() vs JavaScript click()
- 中文 WebDriver click() vs JavaScript click()
- 한국어 WebDriver click() vs JavaScript click()
- 日本語 WebDriver click() vs JavaScript click()
- हिन्दी WebDriver click() vs JavaScript click()
Rome | 2023-01-30
io Python module is always a bit confusing 😭 WebDriver click() vs JavaScript click() is not the only problem I encountered. Checked yesterday, it works!
Boston | 2023-01-30
Simply put and clear. Thank you for sharing. WebDriver click() vs JavaScript click() and other issues with Python functions was always my weak point 😁. I am just not quite sure it is the best method
Moscow | 2023-01-30
code Python module is always a bit confusing 😭 WebDriver click() vs JavaScript click() is not the only problem I encountered. Will get back tomorrow with feedback