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?

  • Does this answer your question? [How to get text of an element in Selenium WebDriver, without including child element text?](https://stackoverflow.com/questions/12325454/how-to-get-text-of-an-element-in-selenium-webdriver-without-including-child-ele) – Moon Cheesez May 09 '20 at 13:54

1 Answers1

1

You need only write "text" in end.

driver.find_element_by_css_selector('div.class-two').text
dimay
  • 2,768
  • 1
  • 13
  • 22