1

This is the HTML code from where I need to extract the text:

<li class="inline t-24 t-black t-normal break-words">
Nilesh Sengupta
</li>

This is my code:

items = driver.find_elements_by_tag_name("li")
print(items.text)

2 Answers 2

3

driver.find_elements_by_tag_name("li") returns a list of web elements
So in order to extract texts from all the elements you have to iterate on all the elements in the list and extract text from each one.
So you should

items = driver.find_elements_by_tag_name("li")
for el in items:
  print(el.text)

In case you want to extract a text from a specific element you should use find_element_by_tag_name instead of find_elements_by_tag_name.
In this case
item = driver.find_element_by_tag_name("li")
item is a web element and you can extract a text from it directly by print(item.text)

Sign up to request clarification or add additional context in comments.

Comments

1

With css selectors is the best way:

tag_list = driver.find_elements_by_css_selector(".inline.t-24.t-black.t-normal.break-words").text

Comments

Your Answer

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.