0
<div class="class-one">
<div class="class-two">
sample text
<div class="class-three">
<a href="https://google.com" target="" class="button button--outline button--purple " id="" title="search"><i class="fal fa-fw fa-file-word"></i><span class="button__title">search</span></a>
</div>
</div>
</div>

When i do driver.find_elements_by_css_selector('div.class-two') it prints sample text and search too, how can i get only sample text using selenium in python?

1

1 Answer 1

1

You need only write "text" in end.

driver.find_element_by_css_selector('div.class-two').text
Sign up to request clarification or add additional context in comments.

4 Comments

AttributeError: 'list' object has no attribute 'text'
Change find_elements_by_css_selector to find_element_by_css_selector
it also shows sample text and search, but i need only sample text
driver.find_element_by_css_selector('div.class-two').text.split("\n")[0]

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.