I have an situation where after clicking on "OK" button Page A and Page B opens. Sometimes page A is triggering an error message(error message is associated with OK button). If I click on OK button Page B is opening. I need to write the code in a way like that "clicking on error message" as optional. Except "OK" button on error message there is no title or anything. Can someone help me on this. Appreciate your help. Thanks
Asked
Active
Viewed 131 times
-1
-
Is this question related to feature file or a logic in Java class file ? Please use @ to reply – cruisepandey Aug 24 '21 at 07:42
1 Answers
2
In your code you can wait for some element appearance for some timeout period and if the element is appeared to perform some actions.
You can define method like this (or similar).
This method waits for visibility of element located by passed XPath locator
public boolean waitForElementToBeVisible(String xpathLocator, int delay) {
WebDriverWait wait = new WebDriverWait(driver, delay);
try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathLocator)));
return true;
}catch (Throwable t) {
return false;
}
}
With this method you can make some logic like this:
if(waitForElementToBeVisible("//button[text()='OK']"),5){
//perform actions you want to do if the OK button appeared
}

Prophet
- 32,350
- 22
- 54
- 79