This issue is due to the chrome driver
always clicks
the middle of the element
in attempt to be faithful to what an actual user does.
So i was thinking of this approach:
First instead of locate an element and click:
driver.fineElement(By.xpath("bla bla")).click()
Write generic function that click on WebElement
:
def clickOnWebElement(WebElement webElement) {
int counter = 0;
boolean isClicked = false;
Thread.sleep(1000);
try {
while (count < 2 && !isClicked) {
if (count == 0) {
webElement.click()
isClicked = true;
}
else if (count == 1) {
Actions action = new Actions(driver);
action.moveToElement(webElement).click().perform();
isClicked = true;
}
else if (count == 2) {
JavascriptExecutor js =(JavascriptExecutor)driver;
js.executeScript("window.scrollTo(0,"element.getLocation().x+")");
webElement.click();
isClicked = true;
}
}
}
catch(Exception ex) {
count++;
Thread.sleep(2000);
}
}
And then when this exception occurs try different way to click.
You think this approach can work ?