0

I am going deeper into regression tests in my company. We have a lot of locators set on span elements combined with click() which causes exception 'not clickable element'. Click on span sometimes works but not always. I am looking for best way to fix our problem. 1. Changing every span elements to buttons. 2. Adding test-id to span or parent(div) element 3. Adding 'actions.moveToElement' but it will be implemented in many places

Do my points have sens for you ? What do you suggest ?

1 Answers1

2

As an option you can use JavaScript.

WebDriverWait wait = new WebDriverWait(driver, 20);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click()", wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(""))));

You can put executeScript to method and use it, here is example of generic click:

public void click(WebDriver driver, WebElement element, boolean withJS){
    if (withJS){
        ((JavascriptExecutor) driver).executeScript("arguments[0].click()", element);
    } else {
        element.click();
    }
}
Sers
  • 12,047
  • 2
  • 12
  • 31