It is a fact that I can locate the exact elements I want with this XPath:
//table[@class="summary-table"]/tbody/tr/*/*/*/a[contains(@class, "snippet-title")]
I know this because I have an XPath plugin that highlights detected elements.
I want to split this element traversal into two parts. The first
part returns a list of tr
cells and the second part does a search in
each tr
cells for the a
within each one of interest.
The first part to return the tr
cells is written and working:
@property
def product_elements(self):
xpath = '//table[@class="summary-table"]/tbody/tr'
elems = self.driver.find_elements_by_xpath(xpath)
return elems
However, I have tried various XPath and css selectors in the code below:
@property
def product_names(self):
xpath = '//a[contains(@class, "lc-snippet-title")]'
for product_elem in self.product_elements:
elem = product_elem.find_element_by_css_selector('.lc-snippet-title')
logging.debug("Found this element {0}".format(
self.pretty_printer.pformat(elem)))
yield elem.text
and nothing is working to find the a
that I want within the tr
WebDriver element.
Because there are multiple a
tags within the tr
, I must find the
one I want by the class attribute.