2016-07-14 7 views
0

Ich habe dieses Problem in Appium, wo die AndroidDriver nicht auf die OK-Schaltfläche (android.widget.Button[@text='OK']) im catch-Block warten, um zu erscheinen. Hier ist der Code:Treiber wartet nicht auf Element, um sichtbar zu sein

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!)"); 
      } 
     } 
    } 

Obwohl ich es Set für 120 Sekunden zu warten, habe ich noch diesen NoSuchElementException Fehler:

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 

Hier wird die appium Protokolle:

> 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 

Ich habe andere Methoden unter ExpectedConditions wie elementToBeClickable und dergleichen versucht. Auch verwendet Thread.sleep(). Ich weiß immer noch nicht, was das verursacht. Ist mein Treiber für diesen Fehler ein Zeitlimit? Wenn die Codes, die ich gepostet habe, nicht genug sind, frage einfach und ich kann mehr posten. Danke im Voraus!

+0

können Sie die Initialisierung tauschen, bevor wartet ein Teil des Elements Initialisierung sein. wait.until (ExpectedConditions.visibilityOf (driver.findElementByXPath ("// android.widget.Button [@ text = 'OK']"))); clickOK.click(); – karthick23

+0

Ich werde es versuchen. tut dies sofort – Daniel

+0

Fehler tritt immer noch auf. Haben Sie andere Ideen dazu? – Daniel

Antwort

0

warten, bis sollte

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

@ karthing23 Hallo, leider konnte ich in den letzten Tagen nicht antworten. Ich kann Code nicht testen, weil ich nicht im Büro bin. Aber das hat funktioniert! Danke vielmals! – Daniel

Verwandte Themen