给定此XML,XPath将返回其prop属性包含的所有元素Foo(前三个节点):
<bla>
<a prop="Foo1"/>
<a prop="Foo2"/>
<a prop="3Foo"/>
<a prop="Bar"/>
</bla>
Run Code Online (Sandbox Code Playgroud) 如何使用xpath为Webdriver获取第一个表(table1)?
<span id="dynamically generated id" data-id="table1">
<table>
...
</table>
</span>
<span id="dynamically generated id" data-id="table2">
<table>
...
</table>
</span>
Run Code Online (Sandbox Code Playgroud)
我能够获得所有data-id元素,但我想在其中过滤文本table1以获得确切的元素.
这没用!
driver.findElement(By.xpath("//@*[starts-with(name(),'data-id') [contains(text(),'table1')]]"));
Run Code Online (Sandbox Code Playgroud) 任务
我想使用Python来对XML数据进行全文搜索.
示例数据
<elements>
<elem id="1">some element</elem>
<elem id="2">some other element</elem>
<elem id="3">some element
<nested id="1">
other nested element
</nested>
</elem>
</elements>
Run Code Online (Sandbox Code Playgroud)
基本功能
我想要的最基本的功能是在XPath中搜索"other"("/ elements/elem")至少返回匹配元素(elem 2)的ID属性值和嵌套元素(elem 3,嵌套) 1)或匹配的XPath.
理想的功能
解决方案应该灵活且可扩展.我正在寻找这些功能的可能组合:
题
我不希望有一个具有所有理想功能的解决方案,我必须结合不同的现有功能并自己编写代码.但首先我想更多地了解那里有什么,你通常会使用哪些库和方法,它们的优点和缺点是什么.
编辑:感谢您的答案到目前为止,我添加了细节并开始了赏金.