Python Selenium - source code reading

Hello!

I’ve a problem - I need to find element by class (let’s say class=“hello”) and Selenium Python reads this source code from the top to the bottom - how can I reverse it? How to make Selenium read this code from the bottom () to the top ()? The element with that class I’m looking for is nearly on the bottom of the source code, but Selenium finds the first one from the top… :frowning:
Thanks for any help :slight_smile:

Hi there!

Have you considered using a different select method instead, like by XPATH ?

Of course, but it’s not helping - tried Xpath and Class but I’m not quite sure how does XPath work - any teaching sites?

This is from the Selenium docs, and it helped me a lot with using XPATH:

Thanks - that helped me a bit, but I still don’t know how to locate the element… Look, here’s how the code looks (more or less):

<!DOCTYPE html>
<html>
<head></head>

<body>
<div>
<div class="c"></div>
<div class="c"></div>
<div class="c"></div>
<div class="c"></div> <--that's the one I want to find, but the one that is found is the first one :(
</div>
</body>
</html>

Try this:

driver.find_element_by_xpath("//body/div/div[4]")

I added some text to the div element you need to locate, and was able to find it using that code.

Let me know if it works!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.