学习的内容如下,通过默认路径,指定路径打开IE,火狐,打开URL,得到当前网页的title和URL,关闭浏览器

打开火狐浏览器:

package selrctest;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class OpenFirefox {

public static void main(String[] args) {

//打开指定路径的火狐浏览器

//因为不是默认的安装路径,需要将fire.exe配置到系统变量去

//System.setProperty("webdirver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");

//WebDriver driver = new FirefoxDriver();

// 打开默认安装路径的火狐浏览器

WebDriver driver = new FirefoxDriver();

刚开始因为火狐最新版本游览器与selenium版本不兼容,导致报错,使用了火狐24.0版本的浏览器就正常了!

打开IE浏览器:

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.openqa.selenium.remote.DesiredCapabilities;

public class OpenInternet {

public static void main(String[] args) {System.setProperty("webdriver.ie.bin","C:\\Program Files\\Internet Explorer\\iexplore.exe");

WebDriver driver = new InternetExplorerDriver();

}

}

自学的资料上说打开IE的方法与火狐的方法一致,就这样照葫芦画瓢,然后报错了!

报错提示如下:

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html

at com.google.common.base.Preconditions.checkState(Preconditions.java:177)

at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)

at org.openqa.selenium.ie.InternetExplorerDriverService.access$1(InternetExplorerDriverService.java:1)

at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.build(InternetExplorerDriverService.java:230)

at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:251)

at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:172)

at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:146)

at selrctest.OpenInternet.main(OpenInternet.java:15)

百度了下才知道打开指定路径的IE浏览器时,需要下载一个IEDriverServer.exe,并放到IE安装目录下。

貌似除了火狐这个原配外,其他的浏览器都需要这样

弄完IEDriverServer.exe后将代码修改成如下:

//打开指定路径的IE浏览器

//将IEDriverServer.exe配置到系统变量中

System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\IEDriverServer.exe");

WebDriver driver = new InternetExplorerDriver();

但是还是报错,报错提示如下:

Started InternetExplorerDriver server (32-bit)

2.43.0.0

Listening on port 31235

Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 2.18 seconds

Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'

System info: host: 'DELL-PC', ip: '172.18.126.129', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'

Driver info: org.openqa.selenium.ie.InternetExplorerDriver

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:422)

at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)

at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:162)

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)

at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)

at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:225)

at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:182)

at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:174)

at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:146)

at selrctest.OpenInternet.main(OpenInternet.java:15)

百度了一下,然后从

这篇文章中了解到,原来是IE保护设置的较高导致,根据文章中的方法一,将IE的保护设置为中后可以打开IE浏览器

然后又试了下方法二添加了设置IE的Capabilities的代码,同样可以正常打开IE浏览器

代码如下:

System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\IEDriverServer.exe");

DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();

ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

WebDriver driver = new InternetExplorerDriver(ieCapabilities);

// 打开默认路径的IE浏览器

WebDriver driver = new InternetExplorerDriver();

//URL输入http://bbs.51testing.com/forum.ph   也可将url变成一个对象,将参数传入driver.get方法中

//String url ="http://bbs.51testing.com/forum.php";

//driver.get(url)

driver.get("http://bbs.51testing.com/forum.php");

//得到当前网页title

String title = driver.getTitle();

//得到当前网页URL

String currentUrl = driver.getCurrentUrl();

//打印title和url

System.out.println(title+"\n"+currentUrl);

//关闭浏览器  也可以使用 driver.close();

driver.quit();

LRC软件测试自学,自学selenium笔记一 - kael的个人空间 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...相关推荐

  1. 南柯服务器压力,性能测试的数据解释及分析 - Mr.南柯 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...

    顾名思义,测试服务(服务,服务,其他网络应用服务,本地服务)的性能如何?如何衡量性能?最表面的无非就是看能支撑多少个用户同时使用该服务.且关注用户使用过程中的用户体验. U.^*A+Mb6{*z@0T ...

  2. 软件测试bug日志信息,软件测试bug收集策略 - Mr.南柯 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...

    51Testing软件测试网$Bu6gaT_ Error = 0 的程序是不存在的,怎样收集和处理程序中的错误?怎样更好地利用错误信息的收集和反馈来协助程序的调试?怎样让产品发布后,用户能够反馈出更有 ...

  3. 软件测试影响与分析,软件测试效率影响因素分析 - Mr.南柯 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...

    方法是影响测试效率的主要因素之一.此外,人为因素.软件类型.缺陷数量.测试充分度等都会对测试效率产生影响.下面对这些因素作一个简要分析.51Testing软件测试网@&WMh,K#qdoq$~ ...

  4. 移动终端软件测试基础知识,移动终端软件测试基础知识 - Mr.南柯 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...

    51Testing软件测试网%aa8|5^'O 1)定制终端评测趋势51Testing软件测试网4Vx+Mx vLl*O*} M3uNE2H^,\`u4B0● 定制终端评测2dq,}Ak|q051Te ...

  5. 安装OTP软件测试自学,OTP的使用技巧 - mike00088的个人空间 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...

    这是从兰兰的论坛上找来的,这些内容对我有很大的帮助,所以我就把它粘来了,以备不时之需.. 1.runaction后面能不能接变量(动态调用action,所以从取数据做action名字了,但是调用总是找 ...

  6. 小鸡对话软件测试自学,lee1241 日志 - lee1241的个人空间 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...

    学习vbs 要点(1): 1) 注释(以REM或\'开头)行在程序中不起作用, 但能让别人更容易读懂你的程序. 2) 变量好像一个盒子, 或一个代号, 可以代表你想代表的东西. 变量赋值使用" ...

  7. java对import语句_Java的import语句 - 不积跬步,无以至千里 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...

    51Testing软件测试网]2S+K"rZ/bP*j 程序员可以使用两种import语句:51Testing软件测试网o$UN5EQh 3oZc4n f9P"CoQ;T]0单类型 ...

  8. linux网络状态检测libcurl,使用curl进行网络诊断 - msnshow的个人空间 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...

    "]J n S%fr6v8G[,zP0   我们使用浏览器插件,很容易查看到网页细分请求消耗的时间.如Firefox的Firebug插件:51Testing软件测试网c[5fs{.Y51Te ...

  9. 压力测试软件 loadr,初学abench压力测试 - 玄大冰 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...

    51Testing软件测试网-e-np9S8o*W|pO+L0t [admin@dn128015 loadtest]$ ./abench1751Testing软件测试网'n c/]/J3L usage ...

最新文章

  1. maven jar包冲突常见报错及解决方法
  2. 量子计算赛道上的巨头拉锯战
  3. 一点历史--Python
  4. wPaint在线绘图插件
  5. python softmax函数
  6. 怎样把java换主题_java – 如何在切换主题时考虑变化?
  7. libsvm matlab 调参数,matlab – 使用libsvm调整svm
  8. 深入剖析ASP.NET的编译原理之二:预编译(Precompilation)
  9. go语言var 和make_Var和语言设计
  10. 经常使用的 WEB server
  11. 计算机键盘换挡键,电脑键盘上的换挡键是哪个
  12. 可视化操作和命令化操作
  13. DirectX11 SDK 下载地址
  14. 如何用微信小程序,每天给自己赚个鸡腿?
  15. 蓝湖 Axure 墨刀
  16. 计算机上安装的网络协议,怎么安装网络协议
  17. 如何解决php curl curl_errno返回6 无法解析主机
  18. 【软件质量保证与测试】2.4软件测试与软件开发的关系
  19. C# 线程的挂起与唤醒 (AutoResetEvent,ManualResetEvent)
  20. PyFlink 教程:PyFlink DataStream API - state timer

热门文章

  1. 超融合架构和服务器虚拟化是什么关系?超融合厂商提供什么样的服务器虚拟化?...
  2. java公交线路查询系统计算机毕业设计MyBatis+系统+LW文档+源码+调试部署
  3. 把知乎丁香医生的文章及回答转pdf
  4. mldonkey系列之四──Mldonkey命令解释[zt]
  5. 实现BL616 wifi 蓝牙免密连接
  6. 点云(刚性)配准--icp
  7. 【智慧农业】农业众筹app,共享农场土地租赁,果树家禽认养小程序,智慧农业小程序源码定制开发和二次开发哪个更合适呢?
  8. 大数据实时+离线项目架构----智慧物流大数据平台(超流行框架!)
  9. vcruntime140_1.dll丢失的解决方法
  10. Onenote如何快速实现首行缩进的功能。