English 中文(简体)
ium: 是否可能在 se定位器中使用reg。
原标题:selenium: Is it possible to use the regexp in selenium locators

我想得到与某些定期表述相匹配的文本的所有散射/链接的xpath。 例如:

<span> day 2 night </span>
<span> day 4 night </span>
<span> day 17 night</span>

我谨呼吁:

sel.get_xpath_count( regexp:day d night )

返回 2. (这当然是一个简单的例子,我愿使用各种定期表达方式)

这是可能的,是怎样做的?

最佳回答

利用<代码>dom=,允许您使用javascript。 j印有:

# sorry, example in Perl:
$sel->get(qq{dom=(function(){
    var x = document.getElementsByTagName( span );
    var result = [];
    for (var i=0;i<x.length;i++) {
        var txt = x[i].innerHTML;
        if (txt.match(/day d night/)) {
            result.push(x[i]);
        }
    }
    return result;
})()});
问题回答

只有在XPath2中才有定期表述。 如果在你使用的浏览器中可以找到XPath 2,那么以下工作应当:

get_xpath_count("xpath=//div*[matches(text(), "day \d night")]");

然而,我认为, Java版将XPath 1.0用于 Sel。 因此,撰写小 Java字功能以 gr除网页上的所有内容,并经常在 Java字中表达,而且这一功能只是将相应数目退回。 然后,你可以使用<代码>get_eval称这一 Java字功能。

也可以获得母子/母体(通过DOM定位器)的超文本页面来源或内装超(通过DOM定位器),然后通过你的节目语言将XML改为DOM物体。 从那里看,你可以同你一起处理OMS(第1或第2版)的问题,以便了解你的愿望。 然后,你可以将结果(例如计票)与 Sel一起做一些事情。

采用这种办法,你只受到你提供的任何方案语言的限制。





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签