python - Selenium get text from a table cell (td) with XPath -


the element <td>20175</td>

xpath of element //*[@id="body"]/table/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table/tbody/tr[4]/td[1]

i want take 20175 part.

i tried

  elems = browser.find_elements_by_xpath("""//*[@id="body"]/table/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table/tbody/tr[4]/td[1]""")    print (elems) 

but gave me not text.

selenium.webdriver.remote.webelement.webelement (session="77dc0a7bef8dadbf9aec1ddbab9e3a91", element="0.027053967816755176-1")>] 

what see printed webelement instance string representation. instead, .text:

elem = browser.find_element_by_xpath("""//*[@id="body"]/table/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table/tbody/tr[4]/td[1]""") print(elem.text) 

or, if there multiple elements matching locator:

elems = browser.find_elements_by_xpath("""//*[@id="body"]/table/tbody/tr[1]/td/table[2]/tbody/tr/td[2]/table/tbody/tr[4]/td[1]""") print([elm.text elm in elems]) 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -