0

How should I use driver.find_elements_by_xpath() to get all the data-row elements that I boxed in the picture.

enter image description here

I do not need the other tr tags. In my current code I just check all the tr tags and then throw out the ones that raise a NoSuchElementException but that gets very slow since my implicit_wait() is set to 15 seconds and the table is about 100 rows long, see below for code snippet.

table_element = t_find_element_by_id(driver, "table_name")
body_element = t_find_element_by_tag_name(table_element, "tbody")
row_elements = t_find_elements_by_tag_name(body_element, "tr")
for item in row_elements:
    column_elements = t_find_elements_by_tag_name(item, "td")
    try:
        a_tag_element = t_find_element_by_tag_name(columns[0], 'a')
    except NoSuchElementException:
        continue

1 Answer 1

1

Try using the below xpath.

//table[@id='table_name']//tbody//tr[not(@class)]

This will give you the highlighted tr tags.

Java Example:

List<WebElement> elements = driver.findElements(By.xpath("//table[@id='table_name']//tbody//tr[not(@class)]"));
for (WebElement ele : elements) {
System.out.println(ele.getText());
                        }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.