【问题标题】:selenium: a custom locator that uses xpath locatorselenium:使用 xpath 定位器的自定义定位器
【发布时间】:2010-10-30 16:33:49
【问题描述】:

我想用 selenium 定义一个自定义定位器,并且我希望它使用现有的 xpath 定位器。

下面的代码不起作用。我该怎么做?

PageBot.prototype.locateElementByNg= function(text, inDocument) {
    var xpath = doSomeManipulation(text);
    return PageBot.prototype.locateElementByXpath(xpath, inDocument);
};

【问题讨论】:

    标签: testing web-applications xpath selenium


    【解决方案1】:

    看看 chrome://selenium-ide/content/locatorBuilders.js

    快速解决方案如何基于 xpath:attributes one 构建自己的:

    LocatorBuilders.add('xpath:attributes', function(e) {

    只需将名称更改为 'xpath:by_ng'

    并将其用作首选属性中的唯一一个 const PREFERRED_ATTRIBUTES = ['by_ng'];

    然后在

    中使用

    LocatorBuilders.order = ['xpath:by_ng','xpath:link'];

    我将为:

    <a id="some" name="other" by_ng="this will be catched">test</a>
    

    如果您需要它来使用以下结构:

    <a id="some" name="other" by_ng="this will be catched">
      <img />
      <span>Text</span>
      <p>Some text <b>bold</b></p>
    </a>
    

    那么将需要一些额外的更改。

    【讨论】:

      猜你喜欢
      • 2011-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-05
      • 2015-01-19
      • 2021-04-11
      • 1970-01-01
      相关资源
      最近更新 更多