I'm trying to use relative locators in selenium 4, but I'm not having much luck with it.
I found an example here, but even though I'm able to find the first element, the second line doesn't work and it seems to be stuck there (I cannot close the browser automatically afterwards).
decision_div = browser.find_element(By.CLASS_NAME, "decisions")
conclusion_div = browser.find_element(locate_with(By.TAG_NAME, "div").below(decision_div))
How can I get it to find the next div right below the one with the specified class name?
Selenium 4 relative locators are dealing with pair of web elements with the similar size and adjacent positions, not what you are trying to do here.
In this case the
div
element you are trying to locate is similarly nested below the parent element located bydecisions
class name.So, you can simply locate the
conclusion_div
element with this code line:But since the locator above gives 13 matches and I don't know which of them you want to locate it could be:
Or maybe
Or maybe