Skip to content
Advertisement

Get the text from parent element only (without text from children elements) using Selenium in Python?

Trying to get the number “6” from this html:

JavaScript

Using this Selenium code:

JavaScript

Getting the result from element:

JavaScript

I.e. both the parent and the child elements text.

Advertisement

Answer

Try this xpath : .//div[@class=’sc-fAyiZu hNLuuN’].getAttribute(“innerText”).split(“”)[0]

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement