简体   繁体   English

用属性和文本写 Xpath

[英]Writing Xpath with attribute and text

I'm a newbie to Selenium and I need to be able to xpath the following element with attribute and text.我是 Selenium 的新手,我需要能够 xpath 以下带有属性和文本的元素。

I am using我在用

//*[text()='Over Due'] 

but I need it with attribute also to narrow it down to the single element.但我也需要它的属性来将它缩小到单个元素。

<div style="padding-right: 10px;"><mat-icon role="img" class="mat-icon notranslate timer-gray material-icons mat-icon-no-color" style="vertical-align: bottom;" aria-hidden="true" data-mat-icon-type="font"> av_timer </mat-icon> Over Due </div>

You can use attribute with your existing XPath like您可以将属性与现有的 XPath 一起使用,例如

//*[text()='Over Due' and @attribute='']

OR with child expression also或者也有孩子的表达

//div[text()='Over Due' and *[text()='some text']]

Try the following XPath-1.0 expression which includes the text node and part of the attributes:尝试以下包含文本节点和部分属性的 XPath-1.0 表达式:

//div[normalize-space(text())='Over Due' and contains(@style,'padding-right: 10px;') and contains(mat-icon/@class,'mat-icon')]

If this does not suffice, add further contains(...) expressions.如果这还不够,请添加更多contains(...)表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM