这是 HTML
通过硒我可以简单地获得innerHTML,但不能获得包括div“cont”在内的整个html
<div id="cont" class="container_CssClss">
<div class="Header_CssClss"> Title... </div>
<div class="Url_CssClss"> www.example.co.il </div>
<div class="ResConent_CssClss"> bla.. </div>
</div>
试图解决这个问题我找到了向文档注入 jQuery 支持的方法
通过此代码
public static string AddJQueryToDoc(this IWebDriver driver, string jsCommand = "") {
string injectjQuery = @"
function loadScript(scriptUrl)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = scriptUrl;
head.appendChild(script);
/* alert(script.src);*/
}
loadScript('https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js');
loadScript('https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js');
".Replace("\r\n", "");
((IJavaScriptExecutor) driver).ExecuteScript(injectjQuery);
// i have added an option to return the value of the return
if (jsCommand != string.Empty) return (string)((IJavaScriptExecutor) driver).ExecuteScript(jsCommand);
return "No Results returned";
}
jsxcutrPath = openFileDialog1.FileName;
public static string getElmOuterHtmlViaJsExcutr_UsingjQuery(string clsName) {
WebDriver = new FirefoxDriver();
IJavaScriptExecutor jsExcutr;
INavigation nav = WebDriver.Navigate();
nav.GoToUrl(jsxcutrPath);
string jsScrpt_jQ = @"
$('document').ready(function () {
function getCLassName (){
return $('#DivSearchResWraper').attr('class');
}
getCLassName();
});
";
WebDriver.AddJQueryToDoc(jsScrpt_jQ);
}
我怎样才能让实现工作并将 jquery 结果/exectuiton 值返回到我的 C# winforms 应用程序?