Php Selenium-如何仅在特定div中搜索元素?
我的代码中有一个元素,它在许多地方的许多页面上使用。具体来说,它是一个日历元素。此元素包含许多部分,但是,无论在何处使用,这些内部部分始终是相同的。我想做的是搜索calendar元素的内部内容,而不管calendar元素在哪里Php Selenium-如何仅在特定div中搜索元素?,php,selenium,Php,Selenium,我的代码中有一个元素,它在许多地方的许多页面上使用。具体来说,它是一个日历元素。此元素包含许多部分,但是,无论在何处使用,这些内部部分始终是相同的。我想做的是搜索calendar元素的内部内容,而不管calendar元素在哪里 作为一个简化的例子,考虑如下: <div class="not-calendar"> <a href="/not-calendar-link">A Link</a> </div> <div class="cal
作为一个简化的例子,考虑如下:
<div class="not-calendar">
<a href="/not-calendar-link">A Link</a>
</div>
<div class="calendar">
<a href="/calendar-link">A Link</a>
</div>
但这是模棱两可的。我想对A链接文本进行同样的“搜索”,但只在类日历的div中搜索这样的文本。请记住,我不希望直接使用XPath访问calendar div,因为我希望它显示在许多页面的不同位置。我该怎么做呢?多谢各位 Xpath功能非常强大,您是否尝试查看文档
//bbb Selects all bbb elements no matter where they are in the document
aaa/bbb Selects all bbb elements that are children of aaa
aaa//bbb Selects all bbb elements that are descendant of the aaa element, no matter where they are under the aaa element
您要查找的表达式:
//div[@class='calendar']/a
哦,我明白了。我想我对XPath的了解还不够。太棒了,谢谢你!我要打断一下,说css更优越,因为xpath在IE上有主要的性能问题。试试看:我也更喜欢css,因为我习惯了jQuery选择器。
//bbb Selects all bbb elements no matter where they are in the document
aaa/bbb Selects all bbb elements that are children of aaa
aaa//bbb Selects all bbb elements that are descendant of the aaa element, no matter where they are under the aaa element