While trying to print values present within the strong tag using XPath, I'm getting the following exception:

org.openqa.selenium.NoSuchElementException: Unable to locate element: strong

This is my code:

   WebElement eleText = driver.findElement(By.xpath("//strong"));
    String testerName = eleText.getText();

This is my webpage which I'm trying to get values within the strong tag:

<a id="id_109996" class="activity"> 
<strong>heizil</strong>: <label id="sample_label">

Expected output: heizil

If this is not the proper way, can anyone suggest any other way of getting the values present in the strong tag?

  • What is happening after : System.out.println(driver.findElement(By.tagName("strong")).getText()); Jan 16, 2023 at 17:13
  • 1
    thanks it worked!! Jan 19, 2023 at 0:49

2 Answers 2


There are multiple workarounds to handle such scenarios while doing web automation using Selenium. While working in outsourced software testing company and developing frameworks in multiple languages below is the most widely used approach -

WebElement eleText = driver.findElement(By.xpath("//a[@class='activity']/strong")).getText()
String testerName = eleText.getText();
  • Thanks alot noted! Jan 28, 2023 at 16:00

Solution :

  • I have tried accessing the element and get text successfully using


  • Found working as expected
  • Suggestion : Use the xpath as last option and choice. Its not most reliable strategy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.