0

If this is the HTML

<div>
 <div>
  <p class="my-element"></p>
 </div>
<div>
<div>
 <div>
   <p class="the-text"> I want to get this text</p>
 </div>
</div>
<div>
 <div>
  <p class="another-element"></p>
 </div>
<div>
<div>
 <div>
   <p class="the-text"> I DONT want to get this text</p>
 </div>
</div>

and my el is

var el = el.findElement(By.css(".my-element"));

how can I get the p.the-text text?

I need a jquery equivalent of

el.parent().parent().find(".the-text")
Artur Stary
  • 724
  • 2
  • 13
  • 30
  • That jquery won't even work here because, at least with the HTML provided, there is no parent of both elements. Is this the correct HTML? btw. you didn't close a couple divs. What have you tried? – JeffC Aug 23 '15 at 20:52

1 Answers1

0

You can find the element with a single css selector and use getText()

driver.findElement( By.css( '.the-text' ) ).getText( function(textDisplayed ) {
   console.log( textDisplayed ); 
} );
Alister Scott
  • 3,675
  • 24
  • 41