Mary
Mary

Reputation: 797

show error with the following python codes

show error with the following python codes

Error:

print driver.find_elements_by_xpath('.//*[@id="example"]/tbody/tr[1]/td[1]').text
AttributeError: 'list' object has no attribute 'text'

Python Code:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("https://datatables.net/")
print driver.find_elements_by_xpath('.//*[@id="example"]/tbody/tr[1]/td[1]').text

Expected Result :

Airi Satou

Upvotes: 0

Views: 59

Answers (1)

Andersson
Andersson

Reputation: 52685

find_elements_by_xpath returns list of WebElements while you need to extract text from single WebElement.

Either try

print driver.find_element_by_xpath('.//*[@id="example"]/tbody/tr[1]/td[1]').text

or

print driver.find_elements_by_xpath('.//*[@id="example"]/tbody/tr[1]/td[1]')[0].text

Upvotes: 1

Related Questions