【问题标题】:Appium: An element could not be located using Xpath in android hybrid apps?Appium:在 android 混合应用程序中使用 Xpath 无法定位元素?
【发布时间】:2017-05-07 22:09:54
【问题描述】:

我尝试使用 appium 自动化混合应用程序。我使用 Ionic 框架开发了我的应用程序。我已经完成了整个设置。然后我尝试在 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 在 chrome 中进行检查,然后我注意到 ionic 具有使用 ionic serve 直接检查的优势。所以我只是转移到那个地方,然后我又在这里得到了结构。请帮我解决这个问题。

提前致谢。

【问题讨论】:

  • 显示目标按钮的HTML
  • 感谢您的回复,您的意思是 html 检查器。显示按钮
  • 我的意思是提到的元素的确切HTML 代码示例,例如<button>BROWSE MENU</button>...
  • 我更新了我的代码 Mr.Andersson
  • 您能否检查一下您的按钮是否位于iframe 元素内?

标签: android xpath selenium-webdriver appium


【解决方案1】:

我曾经遇到过这个问题,所以我使用了cssSelector,这是测试混合应用程序的好方法!

【讨论】:

  • 嗨,艾玛。如何访问 cssSelector 。将避免一个示例。我实际上是 selenium Web 驱动程序的新手。
  • 试试这个例子! :stackoverflow.com/questions/18288333/…
  • 我会试试的。你能说一下如何在离子框架中将 setWebContentsDebuggingEnabled 设置为 true。切换到 web_view
【解决方案2】:

尝试将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

【讨论】:

  • 嘿,Andersson 先生,您能说一下如何在 ionic 框架中将 setWebContentsDebuggingEnabled 设置为 true。切换到 web_view
  • 抱歉,不知道 ionic 框架是如何工作的 :( css selector 你的按钮可能是 button.button.button-raised-button-balanced.ink-dark.button-block
【解决方案3】:

在您对该按钮执行操作之前,请尝试应用 10 秒等待 [Thread.sleep(10000);]。 如果它工作正常,否则将定位器更改为 cssSelector。

【讨论】:

    猜你喜欢
    • 2018-03-15
    • 2014-07-27
    • 1970-01-01
    • 2015-09-27
    • 2015-12-20
    • 2016-10-25
    • 1970-01-01
    • 2020-05-02
    • 2019-05-01
    相关资源
    最近更新 更多