[英]Is there a way to extract html comment(s) using Selenium / WebDriver?
我需要測試的Web應用程序由框架組成,並且在頁面結束加載時將在結尾處顯示HTML注釋( <!-- some text -->
)。
您可以獲取pagesource並檢查注釋是否存在
_driver.Navigate().GoToUrl("http://mysite.com");
var source = _driver.PageSource;
//check the source of the page to see if the commet is there.
使用XPath選擇器和JavaScriptExecutor獲取所有注釋節點:
WebDriver driver= new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor)driver;
String sText = js.executeScript("return document.evaluate(//comment, document, null, XPathResult.ANY_TYPE, null)").toString();
然后根據需要存儲數據。
參考
如果您使用的瀏覽器使它們可用,則DOM中提供了注釋元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.