eclipse + selenium environment to build

First, install jdk and eclipse

Jdk1.8 installed and configured environment variables, and then download and install the eclipse can be.

Second, download selenium

Download the installation package and extract selenium, selenium 2.53.1 stable version of this paper.

 

 

 

 

Third, the reference to the jar package

 

3.1 New Java Project

 

 

3.2 references jar package

 

Similarly, all the libs jar selenium compressed files in the folder are references to the project to prevent classes during code execution can not find the folder that contains the file libs.

 

 

Fourth, start the IE browser

4.1 Creating drive objects start IE browser:

 

 

Execution Error 1:

 

System attribute set to 4.2 webdriver.ie.driver

IE version download the corresponding driving selenium, IEDriverServer.exe the file copied to the decompressed file src class directory project folder.

 

The webdriver.ie.driver as system properties, as the path taken IEDriverServer value. In the src folder, right-click the file to select IEDriverServer.exe copy qualified name, after Paste as "/Java_web_auto/src/IEDriverServer.exe", just take the relative path "src / IEDriverServer.exe". code show as below:

 

Execution Error 2:

 

Setting IE 4.3 browser security area protected mode consistent

Open IE browser, select Settings -Internet Options - Enable Protected Mode check the results of the safety of the four regions (Internet, Local Intranet, Trusted Sites, Restricted Sites) under no consistent cause an error 2 occurred. The Enable Protected Mode item four areas are checked and applied. Close your browser, executing code again.

 

Execution Error 3:

IE browser zoom ratio of 125%, should be set to 100%.

 

 

4.4 Setting IE browser zoom ratio to 100%

Set page scaling to 100% after you close your browser, executing code again, successfully open the browser and not an error.

 

 

Fifth, start Firefox browser

5.1 Creating a drive object to start Firefox browser

 

Execution Error 1:

wrong reason:

1. Firefox browser installed

2.Firefox installed in a different path, not the default installation path

解决办法:

指定Firefox可执行文件路径

5.2 指定Firefox可执行文件路径

告诉jvm火狐的可执行文件的路径:

 

执行代码,启动Firefox浏览器。

 

注意:

1.selenium 2.x 版本中Firefox不需要驱动文件,因为自带的FirefoxDriver已经实现了驱动功能,例如打开浏览器、定位元素等操作。(selenium 2.53.1 + Firefox 46.0)

2.selenium 3.x 版本需要Firefox驱动文件

 

进入change log可以查看不同的驱动版本对应的selenium版本以及Firefox版本。

 

 

六、启动chrome浏览器

6.1 创建驱动对象启动chrome浏览器

 

执行错误1:

错误原因:

缺少chrome浏览器驱动文件。

解决办法:

下载对应版本驱动文件并将其添加进工程,同IE浏览器设置(1.6.4.2)。

6.2 设置webdriver.chrome.driver为系统属性

 

执行代码,自动打开chrome浏览器。

 

去掉这个提示方法:

win+r运行regedit,找到HKEY_CURRENT_USER\Software\Google\Chrome\TriggeredReset,删除即可。

 再次运行代码,启动chrome浏览器。

 

 

Guess you like

Origin www.cnblogs.com/Nancy-Lee/p/10986324.html