0

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
Alexey R.
11.6k5 gold badges21 silver badges39 bronze badges
asked Sep 20, 2019 at 9:19
2
  • 1
    <h1 _ngcontent-gtj-c13=""> Site-2 <span _ngcontent-gtj-c13="" class="seprator">|</span> Building-1 <!----> </h1> Commented Sep 20, 2019 at 9:22
  • What locators/code have you tried? Commented Oct 14, 2020 at 14:27

2 Answers 2

0

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;
answered Sep 20, 2019 at 11:12
0

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()

answered Oct 16, 2020 at 8:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.