【问题标题】:How to print text using xpath and Javascript executor如何使用 xpath 和 Javascript 执行器打印文本
【发布时间】:2016-09-01 17:19:41
【问题描述】:

我正在尝试在 iOS 设备上执行自动化。 当我尝试以下代码时,

WebElement elements = driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]/UIACollectionCell//*[@name=\"price\"]"));

String string = elements.getText();

System.out.println(string); 

它没有打印输出,但它通过了测试。

谁能帮我用javascript执行器做同样的事情。

【问题讨论】:

  • 在appium的inspector中,显示文本在哪个部分---名称、值还是标签?
  • @noor 我已经尝试过了,有些方法没有获取给定的 xpath。所以我正在尝试使用 javascript 执行器。
  • 使用该元素添加您的 appium 检查器的图像

标签: javascript selenium xpath selenium-webdriver appium


【解决方案1】:

使用如下:

WebElement elements = driver.findElement(By.xpath("use right xpath from inspector"));

String string = elements.getAttribute("value");//if the text is shown in value

String string = elements.getAttribute("name");//if the text is shown in name

String string = elements.getAttribute("label");//if shown in lable

System.out.println(string); 

你可以试试这个:

driver.findElementByName("price");

但你必须从 appium 检查器中选择正确的 xpath。

【讨论】:

  • 如果你想使用执行脚本,你必须添加appium检查器的图像
  • 我在我的答案中添加了一种额外的方法,请检查一下并告诉我
  • 是的,我也认为你的 xpath 是错误的。可能是您缺少标签。如果可能,请添加层次结构屏幕截图
猜你喜欢
  • 2015-12-30
  • 2023-03-17
  • 2012-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-23
相关资源
最近更新 更多