admin管理员组文章数量:1245841
<tr _ngcontent-hse-63="">
<td _ngcontent-hse-63="">
<span _ngcontent-hse-63="">1</span>
</td>
<td _ngcontent-hse-63="">
<span _ngcontent-hse-63="" class="noBr">CKH HOLDINGS</span>
</td>
</tr>
I have the above and I am looking to extract the td elements in Selenium. However, it seems the three alphabets between ngcontent and the number is randomized. I have tried the following based on similar questions on SO ref:
By.xpath("//td[starts-with(@_ngcontent, '_ngcontent-') and ends-with(@_ngcontent, '-63')]");
though I'm not too sure how to continue since the @_ngcontent wouldnt even match any attributes, and I think the starts-with() and ends-with() would be matching against the attribute value instead of the attribute itself.
Is there anyway to resolve this? Just getting by the td element is not possible because there are a lot of other elements on the page.
<tr _ngcontent-hse-63="">
<td _ngcontent-hse-63="">
<span _ngcontent-hse-63="">1</span>
</td>
<td _ngcontent-hse-63="">
<span _ngcontent-hse-63="" class="noBr">CKH HOLDINGS</span>
</td>
</tr>
I have the above and I am looking to extract the td elements in Selenium. However, it seems the three alphabets between ngcontent and the number is randomized. I have tried the following based on similar questions on SO ref:
By.xpath("//td[starts-with(@_ngcontent, '_ngcontent-') and ends-with(@_ngcontent, '-63')]");
though I'm not too sure how to continue since the @_ngcontent wouldnt even match any attributes, and I think the starts-with() and ends-with() would be matching against the attribute value instead of the attribute itself.
Is there anyway to resolve this? Just getting by the td element is not possible because there are a lot of other elements on the page.
Share Improve this question edited Feb 17 at 7:11 pebble unit asked Feb 17 at 7:02 pebble unitpebble unit 1,2144 gold badges10 silver badges27 bronze badges1 Answer
Reset to default 2Browsers only support XPath 1.0, which doesn't support ends-with()
.
You can't use it in selenium. So you have to use contains()
instead.
What you are trying to do can be achieved by the following XPath.
//@*[starts-with(name(),'_ngcontent-') and contains(name(),'-63')]/parent::td
It selects all the td elements that has attribute that start with _ngcontent-
and contains -63
.
本文标签:
版权声明:本文标题:java - How can I check against attribute (not attribute value) starting with prefix and ends with suffix - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740176018a2236432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论