<div class="card-header bg-info">
<h4>Dumpytext</h4>
<h5> Dump text/ mg
<span style="font-size: 0.9rem;">(100mg/ 50mg)</span>
</h5>
</div>
I want to hit the h5 and span data in selenium c# and xpath without index
<div class="card-header bg-info">
<h4>Dumpytext</h4>
<h5> Dump text/ mg
<span style="font-size: 0.9rem;">(100mg/ 50mg)</span>
</h5>
</div>
I want to hit the h5 and span data in selenium c# and xpath without index
Use driver.findElement(By.Xpath(//h5));
and driver.findElement(By.Xpath(//h5));
Given the HTML:
<div class="card-header bg-info">
<h4>Dumpytext</h4>
<h5> Dump text/ mg
<span style="font-size: 0.9rem;">(100mg/ 50mg)</span>
</h5>
</div>
To print the text from <h4>, <h5> and <span> tags you can use either of the following locator strategies:
XPath for <h4> tag:
Console.WriteLine(driver.FindElement(By.XPath("//h4")).Text);
XPath for <h5> tag:
Console.WriteLine(driver.FindElement(By.XPath("//h5")).Text);
XPath for <span> tag:
Console.WriteLine(driver.FindElement(By.XPath("//h5/span")).Text);