Selenium Web自动化-Node.js

Selenium是一款有名的Web应用程序自动测试框架,用于进行功能测试,使用它可以实现自动化Web任务。

本文使用Nodejs,以前还介绍过一个用Python的:

如果你还没有安装Node.js,参考:Ubuntu 16.04 安装 Node.js

# 安装selenium-webdriver

我使用Firefox,好处是不用安装额外的驱动。如果你想使用Chrome或IE,你需要安装driver。

如果你使用最新的Firefox (47+)版本,就目前来说,需要安装新驱动:marionette


Setting up the Marionette executable

Just like the other drivers available to Selenium from other browser vendors, Mozilla has released an executable that will run alongside the browser.

Downloading

You can find the latest executable on the GitHub release page.

Even though the project has been renamed to geckodriver, many of the Selenium clients look for the old name wires. You may need to rename the executable to wires to have it picked up automatically.

Add executable to system path

The Selenium client bindings will try to locate the geckodriver (or wires) executable from the system path. You will need to add the directory containing the executable to the system path.

On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:

On Windows you need to update the Path system variable to add the full directory path to the executable. The principle is the same as on Unix.


# 第一个例子:打开一个网页

Selenium2 Web自动化-Node.js

# 第二个例子:使用google搜索关键子’pornhub’

Selenium2 Web自动化-Node.js


更多信息:http://www.seleniumhq.org/docs/

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注