Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using Selenium and XPATH to extract all rows from a table, but can only get the first row.

Here is what I am doing:

from selenium import webdriver

path_to_chromedriver = '/Users/me/Desktop/chromedriver'
browser = webdriver.Chrome(executable_path = path_to_chromedriver)

url = "http://www.psacard.com/smrpriceguide/SetDetail.aspx?SMRSetID=1055"

browser.get(url)
browser.implicitly_wait(10)

SMRtable = browser.find_element_by_xpath('//*[@class="set-detail-table"]/tbody')

for i in SMRtable.find_element_by_xpath('.//tr'):
    print i.get_attribute('innerHTML')

browser.close()

The SMRtable variable has all the rows in it when I convert to string and print. When I try to loop through it, it throw a not iterable error.

I also tried using browser.find_element_by_xpath('//*[@class="set-detail-table"]/tbody/tr'), but this only gives me the first row. I tried adding [position()>0] after /tr, but still got just the first row.

How can I get all of the rows?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You need find_elements_by_xpath() (watch the "s") instead:

for i in SMRtable.find_elements_by_xpath('.//tr'):
    print i.get_attribute('innerHTML')
share|improve this answer
    
I hate when that happen's'. Thanks. –  Dixon11111 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.