xpath可以正常工作,但只能运行一次,当我再次执行代码时,它会错误地工作

时间:2019-11-06 10:50:19

标签: java if-statement selenium-webdriver

我有一个按钮会停留几分钟,例如15分钟,如果我在给定的时间内单击该按钮,则它将打开一个表单并关闭它。但是当时间结束时,按钮消失,则不应执行任何操作。当我执行此代码时,它只能工作一次,但是当我重复它时,它就不会工作。相反,它会打开其他选项卡。

我已经尝试了if else条件来解决此问题,例如是否显示按钮然后执行代码,如果没有,则将执行else条件。不幸的是,当button消失时,代码的行为非常错误,它将打开不相关的选项卡。 / p>

        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.

0 个答案:

没有答案