How to get absolute XPATH in Python from webelement

168 views
Skip to first unread message

Scott ODonnell

unread,
Jan 10, 2014, 1:02:20 PM1/10/14
to seleniu...@googlegroups.com

I have a python program working that searches an inventory table for input fields.
I use something like this:

XPathString = "//input[@class='smtext']"
inputlist = driver.find_elements_by_xpath(XPathString)

Once I find the input field I'm looking for , I need to inspect the table cell to the left of the input field to see QTY available.

Is there a way I can get the absolute XPATH of the input field webelement so I can adjust it to reference the table cell I need ?
OR
Is there a way to reference the adjacent cell indirectly based on the webelement ?

Any ideas are greatly appreciated.

Scott

David Lai

unread,
Jan 10, 2014, 4:41:36 PM1/10/14
to seleniu...@googlegroups.com
Yes, select the cell, then add a '../..' after the element to pop back up to the parent row, then use a selector to drill back down the adjacent input.

Example:
driver.find_element_by_xpath("//td/span[text()='Address']/../..//input").send_keys("1123 Evergreen Terrace")

Scott ODonnell

unread,
Jan 10, 2014, 5:16:45 PM1/10/14
to seleniu...@googlegroups.com
Thank you. 
I will give that a try. 
I was hoping to avoid having to do another call to find_element_by_xpath but I will take what I can get. :)
--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/2nqTWiOWoyI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/86bfc17b-a515-46c5-b9c4-63f2c198d1db%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages