简体   繁体   中英

How can I select an element by class and text with XPath?

I want to get the a element with xpath by the class dropdown-item and the inner text lalalaaaaaaaaa :

<a _ngcontent-pde-c12="" class="dropdown-item" style="padding:10px">
  <i _ngcontent-pde-c12="" aria-hidden="true" class="fa fa-file-excel" style="color:#207144;font- 
  size:18px;"></i>
&nbsp;&nbsp;lalalaaaaaaaaa
</a>

but there is a problem with the part of the inner text - probably because of the &nbsp;&nbsp; .

Can anyone help me please?

You can use contains in your XPath

xpath = "//a[@class='dropdown-item' and contains(@text, 'lalalaaaaaaaaa')]"

Try with Xpath with help of partial text and class

//a[@class='dropdown-item' and contains(., 'lalalaaaaaaaaa')]

only with partial text

//a[contains(., 'lalalaaaaaaaaa')]

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