Link to home
Start Free TrialLog in
Avatar of Hiro 714
Hiro 714

asked on

Python selenium xpath question

How do I get a whole row data with xpath?
I'm getting only header
Xpath

Title
/html/body/div[2]/div[3]/div[2]/div/form/table/thead/tr/th[2]/a
Data
/html/body/div[2]/div[3]/div[2]/div/form/table/tbody/tr[1]/td[2]/a

Open in new window

Code
Ticket_Titles = driver.find_element_by_xpath('//tbody/tr/td[2]/a')

for Ticket_Title in Ticket_Titles:
    print(Ticket_Title.text)

Open in new window

Error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-182-6e3e609a1ea1> in <module>
      2 Ticket_Titles = driver.find_element_by_xpath('//tbody/tr/td[2]/a')
      3
----> 4 for Ticket_Title in Ticket_Titles:
      5     print(Ticket_Title.text)

TypeError: 'FirefoxWebElement' object is not iterable 

Open in new window

another sample
Ticket_Titles = driver.find_element_by_xpath('//tbody/tr/td[2]/a')

Ticket_Titles.text

Open in new window

Output:
'Export max results to Excel (may timeout)'

Open in new window


SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hiro 714
Hiro 714

ASKER

mhh, still getting this error.


Ticket_Titles = driver.find_element_by_xpath('//tbody/tr/td[2]/a')


for Ticket_Title in Ticket_Titles:
    print(Ticket_Title.text)   

Open in new window



---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-224-b58a730331ce> in <module>
      3
      4 #Ticket_Titles.text
----> 5 for Ticket_Title in Ticket_Titles:
      6     print(Ticket_Title.text)

TypeError: 'FirefoxWebElement' object is not iterable 

Open in new window

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-224-b58a730331ce> in <module>
      3 
      4 #Ticket_Titles.text
----> 5 for Ticket_Title in Ticket_Titles:
      6     print(Ticket_Title.text)

TypeError: 'FirefoxWebElement' object is not iterable

Open in new window

sorry, i'm little lazy to hide a private info.

User generated image
also get this error
User generated image
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
aaaa
Thank you! that was it
Glad to hear that.You can refer this article to use more variety way to locating the elements.

https://selenium-python.readthedocs.io/locating-elements.html

How could I remove this data?
User generated image