Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Selenium find element by link text contains a string with wildcard or regex

I have a HTML snippet like this:

<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

driver.find_element_by_link_text(u'评论*')

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

like image 895
armnotstrong Avatar asked Feb 11 '15 09:02

armnotstrong


1 Answers

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.

like image 67
vks Avatar answered Sep 21 '22 10:09

vks