Skip to content
Advertisement

Selenium on Python unable to locate nested class element

I’m trying to reach a nested class, originally I used xPath but it returned an empty list, so I went through the classes individually, and one of them has an issue where selenium can’t find it.

Up until Price4 it works fine, but it can’t seem to find Price5

up until Price4 it works fine, but it can't seem to find Price5

This is the website's inspector

Advertisement

Answer

So, if you want to get the text from the last element containing the price you can define
String lastPriceXpath = "(//*[@class='css-1m1f8hn'])[last()]"
String lastPrice = driver.findElement(By.xpath(lastPriceXpath)).getText()

The syntax above is in Java but I hope you will be able to convert it to python, it’s quite similar

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