javascript - 使用 WebDriverJS (Selenium) 的示例

标签 javascript c# asp.net-mvc selenium-webdriver

我已经开始学习 WebDriverJs 来测试使用 Javascript 作为脚本语言的网站,网址为 https://code.google.com/p/selenium/wiki/WebDriverJs但一开始就发现一些理解问题。

根据该页面,我必须将 Chrome 驱动程序保存到某个路径。那条路是什么? 该路径如何链接到下面的示例代码?

var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder().
   withCapabilities(webdriver.Capabilities.chrome()).
   build();

driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
 return driver.getTitle().then(function(title) {
   return title === 'webdriver - Google Search';
 });
}, 1000);

driver.quit();
<小时/>

从 NPM 安装

% npm install selenium-webdriver

从源代码构建

 % git clone https://code.google.com/p/selenium/  
      % cd selenium   
     % ./go //javascript/node:selenium-webdriver

什么是 NPN 及相关代码?请解释一下。

附注:我基本上是.Net出身

我还需要做任何设置才能运行上面的代码吗?

例如,任何 JavaScript 文件等

<小时/>

现在我可以安装 selenium-webdriver 然后我将上面的 javascript 代码复制到 js 文件中并尝试使用节点运行它并收到以下错误。我错过了什么吗?

Error while trying to run above javascript code using node

最佳答案

您的文件夹结构似乎有问题。

How do I resolve "Cannot find module" error using Node.js?应该可以帮助您解决问题

关于javascript - 使用 WebDriverJS (Selenium) 的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27121171/

相关文章:

c# - Wp8 应用程序自定义控件,其中有一些动态按钮,在主页上不显示任何内容

javascript - 将 JavaScript 数组中的对象合并为对象

c# - 类型 'Microsoft.Phone.Controls.LongListSelector' 存在于两个 dll 中

c# - 使用类库访问 Windows Azure 存储

asp.net-mvc - 找不到键为 '<key>' 的资源对象。自动部署的 ASP.NET MVC3 应用程序

C# Linq 到 SQL :cannot add an entity that already exists

javascript - 从 JSON 填充列表(不是 HTML)

javascript - 尝试使用 innerHTML 获取 javascript 函数的结果

c# - ScriptManager - RegisterStartupScript(带有 2 个参数)

asp.net-mvc - MVC 3 依赖解析器还是 Ninject MVC 插件?