什么是在我的Appium代码中使用的良好的IF语句
问题描述:
这是该网站的新手,仍然试图解决问题的问题。什么是在我的Appium代码中使用的良好的IF语句
UPDATE 好了,所以做一些改变我的代码后,我现在已经在我的代码这个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();
答
您可以断言下一个预期的元素是否存在于屏幕上。
假定上述两次点击(“查看详细信息&支付”按钮)如果是成功会导致你这个屏幕否则不。
org.junit.Assert.assertFalse(driver.findElements(By.id(good)).isEmpty());
验证在导航到的页面中存在一个带有id
好的元素。然后执行以下操作:
driver.findElement(By.id(good)).click();
+0
好的,你可以看看我的新更新请@nullpointer –
问题是什么? – AntonH
@AntonH更新。仍然试图在本网站上提问。 –
尝试阅读https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/是的,它很长,但非常好的内容。 – AntonH