Skip to content Skip to sidebar Skip to footer

How To Get Text From Nested Span Tag In Selenium

I have below HTML code in my project. I have to find only the text 'One Way'. I have tried below codes but it is returning 'One Way Tab 1 of 2'. I am new in selenium so not sure

Solution 1:

findElement(By.xPath("/button/span[contains(., 'One Way')]").getText()

Could you try finding the element using XPath, as above, to see if that returns correctly?


Solution 2:

Try this:

spans = find_elements_by_tag_name("span")
span1_text = spans[0].get_text()

Post a Comment for "How To Get Text From Nested Span Tag In Selenium"