Python Selenium按链接文本查找元素包含带通配符或正则表达式的字符串

时间:2022-09-27 19:28:13

I have a HTML snippet like this:

我有一个像这样的HTML代码段:

<span class="line S_line1">
  评论
  <em>1</em>
</span>

The thing is that number in <em>1</em> is not predictable or sometime just omit, I want to find this element by

问题是 1 中的数字是不可预测的或有时只是省略,我想找到这个元素

driver.find_element_by_link_text(u'评论*')

But it didn't work, is there a way to do that with a wildcard or regex?

但它没有用,有没有办法用通配符或正则表达式做到这一点?

1 个解决方案

#1


6  

driver.find_element_by_partial_link_text(u'评论')

You can using partial_link_text.This way you can find a link with changing content using some part which is always constant.

您可以使用partial_link_text。这样您可以使用一些始终不变的部分找到包含更改内容的链接。

#1


6  

driver.find_element_by_partial_link_text(u'评论')

You can using partial_link_text.This way you can find a link with changing content using some part which is always constant.

您可以使用partial_link_text。这样您可以使用一些始终不变的部分找到包含更改内容的链接。