Example in Python:
element = driver.find_element_by_id("myid") driver.execute_script("arguments.click();", element)
Example in WebDriverJS/Protractor:
var elm = $("#myid"); browser.executeScript("arguments.click();", elm.getWebElement());
I personally used this workaround without fully understanding why I have to do it and what problems it can lead to.
The essential difference between the two methods is common to all browsers and can be explained pretty simply:
WebDriver: When WebDriver does the click, it attempts as best as it can to simulate what happens when a real user uses the browser. Suppose you have an element A which is a button that says "Click me" and an element B which is a
divelement which is transparent but has its dimensions and
zIndexset so that it completely covers A. Then you tell WebDriver to click A. WebDriver will simulate the click so that B receives the click first. Why? Because B covers A, and if a user were to try to click on A, then B would get the event first. Whether or not A would eventually get the click event depends on how B handles the event. At any rate, the behavior with WebDriver in this case is the same as when a real user tries to click on A.
clickevent directly to A, and B will not get any event.
★ Back to homepage or read more recommendations: