0

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

11
  • 1
    Looks like you need to locate the elements not just by their class name. Please provide the link to the page you are working on and I'll try to give you better locators Commented Apr 4, 2021 at 19:39
  • 1
    I see all the elements containing the price are located by the same class name .css-1m1f8hn Commented Apr 4, 2021 at 19:57
  • 1
    Please let me know if this helped you. Otherwise will try to help more. Commented Apr 4, 2021 at 20:06
  • 1
    (//*[@class='css-1m1f8hn'])[last()] Commented Apr 4, 2021 at 20:11
  • 1
    Is this what you are looked for? Commented Apr 4, 2021 at 20:15

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

It finally worked, thank you so much, and for reference below is the Python equivalent
Test = browser.find_elements_by_xpath("(//*[@class='css-1m1f8hn'])[1]") for value in Test: print(value.text)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.