[英]Appium: An element could not be located using Xpath in android hybrid apps?
我試圖使用appium自動化混合應用程序。我已經使用Ionic Framework開發了我的應用程序。 我已經完成了全部設置,然后嘗試在Mozilla中使用firebug進行檢查。我發現特定按鈕的xpath是//Button[text()='BROWSE MENU']
。
但是當我嘗試使用appium對其進行測試時,找不到它,我的測試失敗了。
driver.findElement(By.xpath("//button[text()='BROWSE MENU']")).click();
FAILED: Loginforsample
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: 5.13 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
我不知道我到底要去哪里。 最初,我嘗試使用WEB_VIEW對鉻進行檢查,然后發現離子具有使用離子服務直接檢查的優勢。 所以我只是轉移到那兒,然后又在這里得到了結構。 請幫我解決這個問題。
提前致謝。
嘗試將Explicit wait
添加到您的代碼中:
//driver.switchTo().frame("put_iframe_id_or_name_here"); //to switch to iframe
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[text()='BROWSE MENU']")));
element.click();
//driver.switchTo().defaultContent(); //to switch back if required
我曾經有這個問題,所以我用過cssSelector
這是測試混合應用程序的好方法!
只需嘗試在應用此按鈕上的操作之前應用10秒鍾,等待[Thread.sleep(10000);]。 如果工作正常,則將定位器更改為cssSelector。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.