Skip to content Skip to sidebar Skip to footer

Find Element By Link Text (ignore Symbols In String) In Python

I am trying to match the string on the web with the string i am passing. String on the web is contain symbols like - , : ; and i am passing string without symbols import time from

Solution 1:

You can achieve this using the xpath. translate is the method that you have to use.

driver.find_element_by_xpath("//a[translate(.,'-',' ') = 'Ant Man and the Wasp']").get_attribute('href')

In your code

driver.find_element_by_xpath("//a[translate(.,'-',' ') = name]").get_attribute('href')

Read more about translate method.

If you want to handle :-; in any order then use the below xpath.

//a[translate(.,'-;:','   ')='Ant Man and the Wasp']

Screenshot:enter image description here

Post a Comment for "Find Element By Link Text (ignore Symbols In String) In Python"