How could I extract the text under <div> and <ul> class using Selenium Java

Viewed 27

I want to extract the text "Hi, Harvey " from the below html source

<div class="col-sm-9>
 <div class="shop-menu">
  <ul clas="navbar-nav">
    ::before
     "Hi, harvey "
      <a href="logout.htm">..</a>
     ::after
   </ul>
  </div>
</div>

I have tried:

driver.findElement(By.linkText("Hi, harvey "))

but couldn't extract it, any suggestions?

1 Answers

This should locate that element

driver.findElement(By.xpath("//ul[contains(.,'Hi, harvey')]"))
Related