执行在C#中使用Selenium的JavaScript的webdriver [英] Execute JavaScript using Selenium WebDriver in C#

查看:3804
本文介绍了执行在C#中使用Selenium的JavaScript的webdriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是如何实现的呢? <一href=\"http://$c$c.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q%3a_How_do_I_execute_Javascript_directly?\">Here它说,Java版本是:

How is this achieved? Here it says the java version is:

WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return document.title");

但我无法找到C#code做到这一点。

But I can't find the C# code to do this.

推荐答案

的对象,方法和属性在.NET语言绑定名称不完全对应于那些在Java绑定。其中一个项目的原则是,每一种语言的结合应该感受自然为那些在语言编码的舒适。在C#中,code你想要执行的JavaScript如下:

The object, method, and property names in the .NET language bindings do not exactly correspond to those in the Java bindings. One of the principles of the project is that each language binding should "feel natural" to those comfortable coding in that language. In C#, the code you'd want for executing JavaScript is as follows

IWebDriver driver; // assume assigned elsewhere
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string title = (string)js.ExecuteScript("return document.title");

请注意,该API的webdriver用于.NET的完整的文档可以在这个链接中找到

Note that the complete documentation of the WebDriver API for .NET can be found at this link.

这篇关于执行在C#中使用Selenium的JavaScript的webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆