Appium:无法在 android 混合应用程序中使用 Xpath 定位元素?
Appium: An element could not be located using Xpath in android hybrid apps?
我尝试使用 appium.i 来自动化混合应用程序,我使用 Ionic Framework 开发了我的应用程序。我已经完成了整个设置 ready.then 我试图在 Mozilla.i 中找到使用 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 在 chrome 中检查,然后我注意到 ionic 具有使用 ionic serve 直接检查的优势。所以我只是转移到那个,我又在这里得到了结构。请大家帮我解决这个问题。
提前致谢。
尝试将 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。
我尝试使用 appium.i 来自动化混合应用程序,我使用 Ionic Framework 开发了我的应用程序。我已经完成了整个设置 ready.then 我试图在 Mozilla.i 中找到使用 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 在 chrome 中检查,然后我注意到 ionic 具有使用 ionic serve 直接检查的优势。所以我只是转移到那个,我又在这里得到了结构。请大家帮我解决这个问题。
提前致谢。
尝试将 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。