How to fetch text for

<h1 _ngcontent-gtj-c13=""> Site-2 
<span _ngcontent-gtj-c13="" class="seprator">|</span> 
Building-1 <!----> </h1>

I have used attribute innerhtml,value,outerhtml,javascript Not able to fetch site name with building name

getting text= Site-2 |
expected =  Site-2 | Building-1
  • 1
    <h1 _ngcontent-gtj-c13=""> Site-2 <span _ngcontent-gtj-c13="" class="seprator">|</span> Building-1 <!----> </h1>
    – priyanka
    Commented Sep 20, 2019 at 9:22
  • What locators/code have you tried?
    – Patrick
    Commented Oct 14, 2020 at 14:27

2 Answers 2


Assuming that class attribute value-seprator for span is unique for the page.

First find the parent element of the "span class="seprator" which is h1

IWebElement option = driver.FindElement(By.XPath("//span[@class='seprator']//parent::h1"));

Now get the innertext of the h1 element using the code.

var textinside = option.Text;

In any software qa company, we can get the locator using any of the 02 ways below:

  1. using xpath
  2. using css selector

In case the locator is not found using this way, we can use Actions class or JavascriptExecutor in order to locate the element. These are the common practices followed in any quality assurance services.

Once we fetch the locator, we can get the text by using the below code: findElement(By.cssSelector()).getText()

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.