//*[contains(@class,'oxd-main-menu-item active') and
(contains(@class,'oxd-main-menu-item-wrapper')/child::a) ]
contains(@class,'oxd-main-menu-item active')
:点击链接
contains(@class,'oxd-main-menu-item-wrapper')/child::a)
:通过 xpath 轴访问链接的父级
//div[contains(@class, 'measure-tab') and contains(., 'someText')]
但我的问题是,我们是否也可以使用 contains 函数之一添加 xpath 轴?
我尝试过的所有内容都已添加到描述中
contains() 函数创建 xpath,如下所示:
//div[contains(@class, 'measure-tab') and contains(., 'someText')]
<li class="oxd-main-menu-item-wrapper" data-v-6475d26d="" data-v-636d6b87="">
<a class="oxd-main-menu-item active" href="/web/index.php/leave/viewLeaveModule" data-v-6475d26d="">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 500 500" role="presentation" class="oxd-icon oxd-main-menu-item--icon" data-v-bddebfba="" data-v-6475d26d="">
<g fill="currentColor">
<path ...></path>
</g>
</svg>
<span class="oxd-text oxd-text--span oxd-main-menu-item--name" data-v-7b563373="" data-v-6475d26d="">Leave</span>
</a>
</li>
所需的<a>
元素:
<a class="oxd-main-menu-item active" href="/web/index.php/leave/viewLeaveModule" data-v-6475d26d="">
位于其父 <li>
元素内:
<li class="oxd-main-menu-item-wrapper" data-v-6475d26d="" data-v-636d6b87="">
要识别元素,您可以使用以下任一定位器策略:
cssSelector:
li.oxd-main-menu-item-wrapper > a.oxd-main-menu-item.active
cssSelector 和 contains 子句:
li[class*='oxd-main-menu-item-wrapper'] > a[class*='oxd-main-menu-item']
xpath:
//li[@class='oxd-main-menu-item-wrapper']/a[@class='oxd-main-menu-item active']
xpath 和 contains():
//li[contains(@class, 'oxd-main-menu-item-wrapper')]/a[contains(@class, 'oxd-main-menu-item active')]
contains()
函数,答案是否定的。该函数返回一个布尔值,并且您无法对其进行 XPath 处理。但是,你可以实现(我认为)你想要的。
代替
(contains(@class,'oxd-main-menu-item-wrapper')/child::a)
,您可以使用:
//*[contains(@class,'oxd-main-menu-item active') and
contains(@class,'oxd-main-menu-item-wrapper') and
child::a ]
测试匹配元素是否具有包含这两个值的类并具有子元素 a
。