简体   繁体   中英

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.

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

//*[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:

//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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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