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– priyanka2019年09月20日 09:22:08 +00:00Commented Sep 20, 2019 at 9:22
-
What locators/code have you tried?Patrick– Patrick2020年10月14日 14:27:53 +00:00Commented 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:
- using xpath
- 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()
Explore related questions
See similar questions with these tags.