Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver "find_element_by_xpath" on WebElement

I'm trying to look up an element using the following line:

elements = driver.find_elements_by_xpath("//div[@class='Display']")

Once i have the elements, which I know there are two of "Display", i want to be able to use the second one and find a specific element inside it, like so:

title = elements[1].find_element_by_xpath("//div[@class='Title']")

However, it always reverts to using the first one. I've stepped through it, and it is finding 2 elements for "Display", so i'm not sure what I'm doing wrong.

Any help would be greatly appreciated.

like image 246
williamtroup Avatar asked Aug 23 '12 14:08

williamtroup


1 Answers

I think you want this:

elements = driver.find_elements_by_xpath("//div[@class='Display']")
title = elements[1].find_elements_by_xpath(".//div[@class='Title']")
like image 95
djc Avatar answered Sep 18 '22 16:09

djc