2017-09-11 29 views
-1

這是該網站的新手,仍然試圖解決問題的問題。什麼是在我的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(); 
+0

問題是什麼? – AntonH

+0

@AntonH更新。仍然試圖在本網站上提問。 –

+0

嘗試閱讀https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/是的,它很長,但非常好的內容。 – AntonH

回答

0

您可以斷言下一個預期的元素是否存在於屏幕上。

假定上述兩次點擊(「查看詳細信息&支付」按鈕)如果是成功會導致你這個屏幕否則不

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

驗證在導航到的頁面中存在一個帶有id好的元素。然後執行以下操作:

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

好的,你可以看看我的新更新請@nullpointer –

相關問題