开发者

How to get the HTML tag of some text on a page using selenium

<div class开发者_StackOverflow="searchSummary floatL">
<span>18</span>
results for "gloves"
</div>

How could i get the tag for '18' using selenium. I am looking to retrieve 'span'.

is that possible and how using selenium and css? thanks


If you are using Selenium with Java, given you have a WebDriver driver, try this:

driver.findElement(By.cssSelector("div.searchSummary.floatL span")).getTagName();

If you wish to make it more dynamic (if you want to find the tag name of a span containing a particular string) use XPath:

driver.findElement(By.xpath("//div[@class='searchSummary floatL']/*[contains(.,'18')]")).getTagName();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜