【问题标题】:Using Selenium and XPath, converting a By element to a string使用 Selenium 和 XPath,将 By 元素转换为字符串
【发布时间】:2012-06-30 09:11:52
【问题描述】:

我有一个接受 By 元素的函数,By by = By.xpath("xpathString")。在我的方法中,我使用以下语句来查找另一个 WebElement

findElement(by).findElements(By.xpath(anotherXPathString))

有谁知道一种方法来操作第一个,以便我可以将它们组合起来,以便我可以使用一个 findElement 函数?我查看了 Selenium By 类页面,它无法将 By 转换为 String 或组合到不同的 By 元素。我的目标是让它看起来像

By newby = (however we will combine the two by statements);
findElements(newby);

String newXPath = (however we convert the by to a string) + anotherXPathString;
findElements(By.xpath(newXPath));

【问题讨论】:

    标签: xpath selenium


    【解决方案1】:

    你知道 ByChained 类吗?

    您可以通过 ByChained 使用来总结 By chain。

    参见:javadoc (http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/pagefactory/ByChained.html)

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2013-02-04
      • 2014-08-30
      • 2012-12-02
      • 1970-01-01
      • 2012-02-28
      • 1970-01-01
      • 2021-04-27
      • 2013-03-03
      • 2017-01-07
      相关资源
      最近更新 更多