user392688
user392688

Reputation: 61

Webdriver in Python: How to get number of rows.columns and data?

Any idea how to get number of rows and columns and data from table? I am using webdriver Python bindings.

I tried different approaches but did not success.

table = self.find_element_by_xpath(id)
trs = self._selobj.find_element_by_tag_name("tr")
print "Getteble 2 "
print "TRS " + trs[1]
tds = trs[1].find_elements(By.TAG_NAME, "td")
print tds[0]
#print table.__len__()
#for(int i=1;i<=list.length;i++)
print "Tesxt 1"
text1 = self._selobj.find_element_by_xpath("//*[@class='general_table']/tbody/tr[2]/td[2‌​]/a").text
print "Tesxt " + text1
#text2 = self._selobj.find_element_by_xpath("//*[@class='general_table']/div["+i+"]/div[2‌​]").text;

Upvotes: 1

Views: 2080

Answers (1)

Deepanjan Acharya
Deepanjan Acharya

Reputation: 11

try this ..

table=driver.find_element_by_xpath("xpath of table")
for tr in table.find_elements_by_tag_name("tr"):
print(tr.text)

Upvotes: 1

Related Questions