[英]Appium: An element could not be located using Xpath in android hybrid apps?
I trying to automate a hybrid app using the appium.i had developed my app using Ionic Framework. 我试图使用appium自动化混合应用程序。我已经使用Ionic Framework开发了我的应用程序。 i had completed the total setup ready.then i tried to find the elements inspecting using firebug in Mozilla.i found the xpath of a particular button is
//Button[text()='BROWSE MENU']
. 我已经完成了全部设置,然后尝试在Mozilla中使用firebug进行检查。我发现特定按钮的xpath是
//Button[text()='BROWSE MENU']
。
but when i try to test it using appium it is unable to find it , my test got failed. 但是当我尝试使用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
i didn't know where exactly i am going wrong. 我不知道我到底要去哪里。 initially i tried WEB_VIEW to inspect in chrome then i noticed that ionic has an advantage of direct inspecting using ionic serve .
最初,我尝试使用WEB_VIEW对铬进行检查,然后发现离子具有使用离子服务直接检查的优势。 so i simply shifted to that and again i got struct here.
所以我只是转移到那儿,然后又在这里得到了结构。 please help me guys to this issue for me.
请帮我解决这个问题。
thanks in advance. 提前致谢。
Try to add Explicit wait
to your code: 尝试将
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
这是测试混合应用程序的好方法!
just try to apply 10 seconds wait [Thread.sleep(10000);] before you are performing the operation on this button. 只需尝试在应用此按钮上的操作之前应用10秒钟,等待[Thread.sleep(10000);]。 if it works then fine otherwise change the locator to cssSelector.
如果工作正常,则将定位器更改为cssSelector。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.