Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find links containing a specific word in case insensitive manner in selenium webdriver

I'd like to be able to find links containing: hello, Hello, hEllo, heLlo, etc. So far I'm using find_elements_by_partial_link_text which is casse sensitive:

links = driver.find_elements_by_partial_link_text('hello')
like image 393
Bryan Torres Avatar asked Mar 18 '23 15:03

Bryan Torres


1 Answers

find_elements_by_partial_link_text() as well as find_elements_by_link_text() are both case sensitive and the behavior cannot be easily changed.

Instead, find links by xpath and apply lower-case() function:

links = driver.find_elements_by_xpath('//a[contains(lower-case(.), "hello")]')

Also see:

  • Is there a way to ignore upper case when trying to find a link by linkText with Webdriver?
like image 167
alecxe Avatar answered Apr 26 '23 07:04

alecxe