如何通过xpath和内部文本获取元素? [英] How to get element by xpath and inner text?
本文介绍了如何通过xpath和内部文本获取元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用xpath和内部文本查找UI弹出窗口.弹出的html是这样的:
I am trying to locate a UI popup using xpath and inner text. The popup html is like this:
Hello ? {some elements} What would you like to do today {more elements} Play or Die ? {Yes button, No button}.
我想通过使用类似这样的东西来获得这个元素:
I want to get this element by using something like this:
//div [contains(@innerText,'你好?今天你想做什么玩还是死?')]
//div[contains(@innerText, 'Hello ? What would you like to do today Play or Die ?')]
我该怎么做?还是有更好的方法来找到此弹出窗口?这里没有ID或永久班级.此外,DOM结构是可变的.
How do I do this ? Or is there a better way to find this popup ? There are no Ids or permanent classes here. Moreover the DOM structure is variable.
推荐答案
您应该能够使用xpath ver2的matchs函数:
You should be able to use xpath ver2's matches function:
//div[matches(text(), 'Hello ?\w+ What would you like to do today \w+')]
哪些允许使用正则表达式.
Which allows regex.
这篇关于如何通过xpath和内部文本获取元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文