2016-07-14 3 views
0

AndroidDriverがキャッチブロックのOKボタン(android.widget.Button[@text='OK'])が表示されるのを待つAppiumでこの問題が発生しています。ここでは、コードは次のとおりです。ドライバが要素が表示されるのを待機しません。

WebDriverWait wait = new WebDriverWait(driver, 120); 
if(networkConnection.wifiEnabled()){ 
     try{ 
      WebElement msg = driver.findElementByXPath("//android.widget.TextView[@text='No network connection detected. Please check your Wi-Fi or mobile settings.']"); 
      if(msg.isDisplayed()){ 
       wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//android.widget.Button[@text='OK']"))); 
       WebElement clickOK = driver.findElementByXPath("//android.widget.Button[@text='OK']"); 
       clickOK.click(); 
       System.err.println("420;Download detailing file using WiFi connection;Application should be able to download the detailing file to the device;(Result=Failed!)"); 
      } 
     } 
     catch(NoSuchElementException e){ 

      wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//android.widget.Button[@text='YES']"))); 
      WebElement clickYes = driver.findElementByXPath("//android.widget.Button[@text='YES']"); 
      clickYes.click(); 
      wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//android.widget.Button[@text='OK']"))); 
      WebElement clickOK = driver.findElementByXPath("//android.widget.Button[@text='OK']"); 
      if(clickOK.getAttribute("text").contains("successfully")){ 
       clickOK.click(); 
       System.out.println("420;Download detailing file using WiFi connection;Application should be able to download the detailing file to the device;(Result=Passed!)"); 
      } 
     } 
    } 

私は120秒間待つようにそれを設定しているが、私はまだこのNoSuchElementExceptionエラーを取得:

Exception in thread "AWT-EventQueue-0" org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 2.42 seconds 

ここではappiumログです:

> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION 
> info: [debug] [BOOTSTRAP] [debug] Got command action: find 
> info: [debug] [BOOTSTRAP] [debug] Finding //android.widget.Button[@text='OK'] using XPATH with the contextId: multiple: false 
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"Could not find an element using supplied strategy. ","status":7} 
> info: [debug] Condition unmet after 2407ms. Timing out. 
> info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"Could not find an element using supplied strategy. "},"sessionId":"147e3950-c6f9-4790-8f6f-e9ed70a9aaa9"} 
> info: <-- POST /wd/hub/session/147e3950-c6f9-4790-8f6f-e9ed70a9aaa9/element 500 2419.570 ms - 230 

私はExpectedConditionsの下に他の方法、例えばelementToBeClickableなどを試しました。また、Thread.sleep()も使用しました。私はまだこの原因を知らない。ドライバのタイムアウトはこのエラーの原因ですか?私が掲示したコードだけでは十分ではないと私はより多くを投稿することができます。前もって感謝します!

+0

はあなたが待っている前に初期化を入れ替えることができ要素の初期化の一部である必要があります。 wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath( "android.widget.Button [@ text = 'OK']"))); clickOK.click(); – karthick23

+0

私はお試しください。すぐにこれを行う – Daniel

+0

エラーがまだ発生します。これについて他のアイデアがありますか? – Daniel

答えて

0

待機するまでは

WebElement clickOK=wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("//android.widget.Button[@text='OK']"))); 
+0

@ karthing23こんにちは、申し訳ありません、私はここ数日で返信することができませんでした。私はオフィスにいないので、テストコードは使えません。しかし、これはうまくいった!どうもありがとう! – Daniel

関連する問題