Abhishek Gupta
Abhishek Gupta

Reputation: 58

Find text of HTML element using selenium WebDriver in Java which has inherited element

I am trying to get text of an element which contains another element in it and a text. But it return something from the inherited element and the text. Is there a way I can get only the text?

enter image description here

Upvotes: 0

Views: 129

Answers (2)

Guy
Guy

Reputation: 50809

The text is in the <h5> tag, you need to locate that element

String text = driver.findElement(By.xpath("//img[@class='img-circle owner-image']/..")).getText();

Upvotes: 2

anshul Gupta
anshul Gupta

Reputation: 1270

Other way of locating element

String text = driver.findElement(By.xpath("//img[contains(@class,'img-circle')]")).getText();

Upvotes: 0

Related Questions