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
asked Jul 4, 2018 at 8:23

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());
 }
answered Jul 4, 2018 at 9:01
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.