I have below HTML code, in that I have to come up with XPath for the 2nd line of text: "Policy Count - 0".
<h2 id ="lblpremiumVol">
"Premium Volume - $"
<br>
"Policy Count - 0"
</h2>
How do I do that?
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.
Sign up to join this communityI have below HTML code, in that I have to come up with XPath for the 2nd line of text: "Policy Count - 0".
<h2 id ="lblpremiumVol">
"Premium Volume - $"
<br>
"Policy Count - 0"
</h2>
How do I do that?
Your xpath would be //h2/text()[2]
. See the test here.
P.S. - I have no idea why you need that xpath (since you're not mentioning that in your question) but as a side note: you will not be able to use this xpath with Selenium since Selenium cannot wrap a text node into a WebElement
If you need that for Selenium, use the following approach:
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
string title = (string)js.ExecuteScript("return document.evaluate('//h2/text()[2]', document, null, XPathResult.STRING_TYPE, null ).stringValue;");