selenium:使用 xpath 定位器的自定义定位器 [英] selenium: a custom locator that uses xpath locator
问题描述
我想用 selenium 定义一个自定义定位器,并希望它使用现有的 xpath 定位器.
I want to define a custom locator with selenium, and I want it to use the existing xpath locator.
下面的代码不起作用.我该怎么做?
The code below does not work. How should I do it?
PageBot.prototype.locateElementByNg= function(text, inDocument) {
var xpath = doSomeManipulation(text);
return PageBot.prototype.locateElementByXpath(xpath, inDocument);
};
推荐答案
看看 chrome://selenium-ide/content/locatorBuilders.js
Have a look at chrome://selenium-ide/content/locatorBuilders.js
如何基于 xpath 构建自己的快速解决方案:属性一:
Quick solution how you can build your own one based on xpath:attributes one:
LocatorBuilders.add('xpath:attributes', function(e) {
LocatorBuilders.add('xpath:attributes', function(e) {
只需将名称更改为 'xpath:by_ng'
just change name to 'xpath:by_ng'
并将其用作 Preferred 属性中的唯一一个const PREFERRED_ATTRIBUTES = ['by_ng'];
and use it as the only one in Preffered attributes const PREFERRED_ATTRIBUTES = ['by_ng'];
然后在
LocatorBuilders.order = ['xpath:by_ng','xpath:link'];
LocatorBuilders.order = ['xpath:by_ng','xpath:link'];
我将为:
<a id="some" name="other" by_ng="this will be catched">test</a>
如果你需要它来处理像这样的结构:
If you need it to work with structure like:
<a id="some" name="other" by_ng="this will be catched">
<img />
<span>Text</span>
<p>Some text <b>bold</b></p>
</a>
然后需要一些额外的更改.
then some additional changes will be needed.
这篇关于selenium:使用 xpath 定位器的自定义定位器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!