Przemo
Przemo

Reputation: 193

"element not interactable" - ElementNotInteractableException is not ignored by FluentWait in Java using Selenium and BrowserStack

I have a class as follows:

public class Utils {
static WebElement fluentWaiter(final By locator,final WebDriver driver) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
        .withTimeout(Duration.ofSeconds(30L))
        .pollingEvery(Duration.ofSeconds(3L))
        .ignoring(org.openqa.selenium.ElementNotInteractableException.class)
        .ignoring(org.openqa.selenium.NoSuchElementException.class);

    WebElement foo = wait.until(
        new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver driver) {
                return driver.findElement(locator);
            }
        }
    );

    return foo;          
};   
}

When I run a code using BrowserStack Safari remote driver I always got an error: "element not interactable" at first attempt to find an element. In console I see following exception:

!!! Eception: Exception: org.openqa.selenium.ElementNotInteractableException: 
!!! Exception message: Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'DESKTOP-9Q3LLM3', ip: '192.168.0.73', os.name: 'Windows 10', 
os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1'    
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [75bb87468c1fc4fa0bce6bf2bf5340d3b165c0d7, clickElement {id=node-94611454-C3E1- 
4019-82F8-76517EA0FBBB}]
Capabilities {acceptInsecureCerts: false, browserName: Safari, browserVersion: 15.1, 
javascriptEnabled: true, platform: MAC, platformName: MAC, safari:automaticInspection: 
false, safari:automaticProfiling: false, safari:diagnose: false, 
safari:platformBuildVersion: 21A559, safari:platformVersion: 12.0.1, 
safari:useSimulator: false, setWindowRect: true, strictFileInteractability: false, 
webdriver.remote.sessionid: 75bb87468c1fc4fa0bce6bf2bf5..., webkit:WebRTC: 
{DisableICECandidateFiltering: false, DisableInsecureMediaCapture: false}}
Element: [[RemoteWebDriver: Safari on MAC (75bb87468c1fc4fa0bce6bf2bf5340d3b165c0d7)] -> 
xpath: //a[@uib-tooltip='Actions'][@class='text-white']]
Session ID: 75bb87468c1fc4fa0bce6bf2bf5340d3b165c0d7

Code that fails:

       try {
          By actionsMenuListView = By.xpath("//a[@uib-tooltip='Actions'][@class='text-white']");
          Utils.fluentWaiter(actionsMenuListView, driver).click();
    } catch (Exception e) {
        System.out.println("!!! Exception: " + e.toString());
        System.out.println("!!! Exception message: " + e.getMessage());
        jse.executeScript(
                "browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\": \"failed\", \"reason\": \"Download file failed\"}}");
        test.log(Status.FAIL, "Download file failed");
        assertTrue(false);
    }

Why FluentWait is not ignoring ElementNotInteractableException within the first 30 seconds?

At the same time the NoSuchElementException is working as expected.

Upvotes: 0

Views: 285

Answers (1)

Przemo
Przemo

Reputation: 193

The problem was with click action. After changing the code to following one:

public class Utils {
  static WebElement fluentWaiter(final By locator,final WebDriver driver) {
  Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
    .withTimeout(Duration.ofSeconds(30L))
    .pollingEvery(Duration.ofSeconds(3L))
    .ignoring(org.openqa.selenium.NoSuchElementException.class);

  WebElement foo = wait.until(
    new Function<WebDriver, WebElement>() {
        public WebElement apply(WebDriver driver) {
            return driver.findElement(locator);
        }
    }
  );

  return foo;          
};   
}

and

try {
    By actionsMenuListView = By.xpath("//a[@uib-tooltip='Actions'][@class='text-white']");
    WebElement element = Utils.fluentWaiter(actionsMenuListView, driver);
    JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
    javascriptExecutor.executeScript("arguments[0].click();", element);
} catch (Exception e) {
    System.out.println("!!! Exception: " + e.toString());
    System.out.println("!!! Exception message: " + e.getMessage());
    jse.executeScript(
            "browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\": \"failed\", \"reason\": \"Download file failed\"}}");
    test.log(Status.FAIL, "Download file failed");
    assertTrue(false);
}

It started to work.

Upvotes: 0

Related Questions