mercredi 6 novembre 2019

xpath works correctly but only once , when i execute code again it works wrongly

I have a button that stays for few minutes ,like 15 minutes , if i click on that button in given time then it opens a form and close it.but when time is over ,button disappear , then no action should perform.When i execute this code ,it works for once , but when i repeat it , it doesn't.Instead it opens somewhat else tab.

I have tried if else condition to sort this problem out , like if button displayed then execute code , if not , then else condition will be executed.Unfortunately , when button disappears , code behaves very wrongly , it opens irrelevant tabs.

        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        WebElement CheckIn=driver.findElement(By.xpath("/html/body/callingdr-app/apptemplate/div/div/div/page-tab/div/p-tabview/div/div/p-tabpanel[1]/div/div/ng-component/div[1]/div/div[2]/div/table/tbody/tr[1]/td[1]/button[1]"));
        if(CheckIn.isDisplayed()) {
            Actions builder=new Actions(driver);
            Action mouseovercheckin=builder.moveToElement(CheckIn).build();
            mouseovercheckin.perform();
            CheckIn.click();
            //Click on next , visit reason
            driver.findElement(By.xpath("/html/body/div[3]/div[1]/span/p-header/div/div[2]/button[1]")).click();
            //Click on next,history
            driver.findElement(By.xpath("/html/body/div[3]/div[1]/span/p-header/div/div[2]/button[2]")).click();
            //Click on next , Payment
            driver.findElement(By.xpath("/html/body/div[3]/div[1]/span/p-header/div/div[2]/button[2]")).click();
            //Close without filling intake form
            driver.findElement(By.xpath("/html/body/div[3]/div[1]/span/p-header/div/div[2]/button[2]")).click();
            System.out.println("CheckedIn successfully");
        }else {
            System.out.println("Appointment overrude , No show");
            }
        }```

Expected result is : when if condition true, form should open and then close.
Actual result: form opens but once ,not every time if button is still there.and if not , then else condition should be executed but it doesn't.

Aucun commentaire:

Enregistrer un commentaire