0

There is a functionality like in sometimes one of modal pops up and there is a button on it. If the modal pops up user needs to click on that button. This is a continuous process and I need to automate it. How to handle this situation using selenium with java? My code is as below,

public void Orders() throws InterruptedException {
    OrdersPage op = new OrdersPage(driver);
    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(),'Reject')]")));
    //op.clickAccept();
    op.clickReject();

How to can I run this one continuously? (may be once a day or until stopped manually)?

4
  • Why do you want to run this continuously? How often does the modal pop open? I'm struggling to understand the use case.
    – Lee Jensen
    Nov 1, 2021 at 20:04
  • Hi @LeeJensen, bcoz this is a web site for a restaurant and we need to accept receiving orders for now. So we cannot assume the modal popup time. modal pops up if someone place an order.
    – Rush910
    Nov 2, 2021 at 5:45
  • @Rush910 Are you using this in a test? Or are you using it in an actual user environment? If it's a test you should have control over the popup time.
    – corsiKa
    Nov 2, 2021 at 5:53
  • hi @corsiKa, This is on actual env.
    – Rush910
    Nov 2, 2021 at 7:09

2 Answers 2

0

You can put your code in a loop to have it run forever. Just add a sleep after each iteration so you don't hammer your CPU and network.

while(true) {
   ... your code
   Thread.sleep(250);
}
0

This scenario is faced mostly in medical device software testing where unwanted pop ups occur on the screen.

Below code will wait for one day(withTimeout wait), if the pop up is displayed early then it will click the 'reject' option from pop up(pollingEvery wait)

FluentWait wait = new FluentWait(driver);

wait.withTimeout(1, TimeUnit.DAYS);

wait.pollingEvery(60, TimeUnit.SECONDS);

wait.ignoring(NoSuchElementException.class);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(),'Reject')]")));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.