2016-07-14 6 views
0

AndroidDriver이 catch 블록의 OK 단추 (android.widget.Button[@text='OK'])가 나타날 때까지 기다리지 않는 Appium에서이 문제가 발생합니다. 나는 120 초 동안 기다리하도록 설정했지만드라이버가 요소가 표시 될 때까지 기다리지 않습니다.

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

, 나는 여전히이 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 

여기에 코드입니다 나는 elementToBeClickable과 같은 다른 방법을 ExpectedConditions과 같은 시도했다. 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 안녕하세요, 지난 며칠간 회신을 드리지 못해 죄송합니다. 저는 사무실에없는 Im 때문에 테스트 코드가 없습니다. 그러나 이것은 효과가 있었다! 고마워요! – Daniel

관련 문제