Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate over a webelement obtained using selenium

rows = driver.find_element_by_xpath("//div[@style='display: block;']//table[@style='display: table;']//tr")

When I try to iterate over rows It throws an error TypeError: 'WebElement' object is not iterable

def get_size(e):

   for  entry in e:

     count = count + 1
   return count

get_size(rows)
like image 422
user3179786 Avatar asked Jan 11 '14 03:01

user3179786


People also ask

How do I iterate through a web table in Selenium?

Code Explanation: Using chrome driver we locate the web table and get total number of row using XPath “.//*[@id='leftcontainer']/table/tbody/tr/td[1]” Using for loop, we iterate through total number of rows and fetch values one by one. To get next row we use (i+1) in XPath.

Is getText () a WebElement method?

What Is getText() Method? The Selenium WebDriver interface has predefined the getText() method, which helps retrieve the text for a specific web element. This method gets the visible, inner text (which is not hidden by CSS) of the web-element.

Can we get XPath from WebElement?

Go to the First name tab and right click >> Inspect. On inspecting the web element, it will show an input tag and attributes like class and id. Use the id and these attributes to construct XPath which, in turn, will locate the first name field.


1 Answers

Try this . This should work. use find_elements_by_xpath

Listlinker = []
Listlinker = driver.find_elements_by_xpath(""//div[@style='display: block;']//table[@style='display: table;']//tr")
for link in Listlinker:
// more code
like image 50
A Paul Avatar answered Sep 27 '22 22:09

A Paul