Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python selenium presence_of_element_located((By.XPATH, ) need case insensitive

I stumbled upon fact then xref maybe in upper case or lower case (even partly) on searched page. How to ensure script finds xref if xref is present on page regardless of case?

Post Python: Selenium xpath to find element with case insensitive characters? talks it's not working, but it was 2013. Hope it's changed. How to write proper expression? My current code is:

myLink = WebDriverWait(myDriver, 
10).until(ExConditions.presence_of_element_located((By.XPATH, 
'//a[starts-with(@href,"https://www.test.org/portal/")]')))
like image 620
Alexei Martianov Avatar asked May 16 '26 22:05

Alexei Martianov


1 Answers

Looks like lower-case(@href) is not working (at least for my Firefox on Windows 7), also not fn:lower-case(@href).

I resort to translate which I've found in posts:

'//a[contains(translate(@href, "ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz"),
"www.test.org/portal")]'
like image 174
Alexei Martianov Avatar answered May 19 '26 11:05

Alexei Martianov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!