How to get text from header having separator



  • 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
    


  • 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;
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2