K
K
Kayuro2021-09-27 18:11:34
selenium
Kayuro, 2021-09-27 18:11:34

How to extract desired rows in Python Selenium?

I am using Selenium to parse test responses, all responses are wrapped in a div text /div tag.
Using just find_elements_by_tag_name is not an option, it will display, consider, the entire page.
How to extract the desired lines with content:
div (1. b) / div - etc etc?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ScriptKiddo, 2021-09-27
@Kayuro

Use find_element_by_xpath
Then select the reference element, if needed, and extract the desired rows from it

table  = driver.find_element_by_xpath('//div[@class="table"]')
rows = table.find_elements_by_xpath('//div')
for row in rows:
    print(row.text())

Or in one xpath if none of the table attributes is required
rows  = driver.find_element_by_xpath('//div[@class="table"]//div')
for row in rows:
    print(row.text())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question