在我的Appium代码中使用什么是好的IF语句

时间:2017-09-11 19:34:40

标签: java automated-tests appium

该网站的新手,仍然试图解决问题。

更新 好吧,在对我的代码进行一些更改后,我现在在我的代码中有这个IF语句,但我的问题是如果IF语句为真,那么它会进入某个页面,但不会点击按钮。我的代码是正确的还是我错过了一些部分?

    driver.findElement(By.id(redButton)).click();

    driver.findElement(By.id(good)).click();

    driver.findElement(By.id(locator)).click();

    //IF statement with variable named "viewdets"
    //If "View Details & Pay" button pops up click
    if (!driver.findElements(By.id(viewdets)).isEmpty()) {
        driver.findElement(By.id(viewdets)).click();
        //App Closes and Doesn't Click Pay Button
        driver.findElement(By.id(pay)).click();
        driver.findElement(By.id(conpay)).click();
    //If not then continue to stall and check in
    } else {
        Thread.sleep(7000);
        driver.findElement(By.id(stall)).click();
        driver.findElement(By.id(two)).click();
        driver.findElement(By.id(three)).click();
        driver.findElement(By.id(next)).click();

        wait = new WebDriverWait(driver, 15);
        wait.until(ExpectedConditions.elementToBeClickable(By.id(pay)));

        driver.findElement(By.id(pay)).click();
        driver.findElement(By.id(conpay)).click();
        driver.findElement(By.id(receipt)).click();

1 个答案:

答案 0 :(得分:0)

您可以断言屏幕上是否存在下一个预期元素。

假设前两次点击("查看详细信息&付费"按钮),如果成功,则会引导您进入此屏幕或否则

org.junit.Assert.assertFalse(driver.findElements(By.id(good)).isEmpty());

验证您导航到的页面中是否存在id良好的元素。然后对其执行操作:

driver.findElement(By.id(good)).click();