前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >selenium-webdriver|2 第一个脚本编写及主流浏览器的启动

selenium-webdriver|2 第一个脚本编写及主流浏览器的启动

作者头像
测试邦
发布2019-07-30 17:07:28
6560
发布2019-07-30 17:07:28
举报
文章被收录于专栏:测试邦

Firefox及firebug的介绍

Firefox

selenium2启动firefox浏览器(不需要下载驱动,原生支持,但版本需要与对应火狐版本按要求对应)课件演示版本是selenium-java-2.53.1.zip,解压后打开CHANGELOG,可看到支持最新火狐版本如下

Firefox全历史版本下载: http://ftp.mozilla.org/pub/mozilla.org//firefox/releases/

Selenium历史版本下载

http://selenium-release.storage.googleapis.com/index.html

firebug的介绍

Firebug是Firefox浏览器一个出色的网页设计插件

Firebug的安装

菜单-添加组件-插件,输入firebug,进行安装即可

新版火狐已经将firebug整合到开发工具,不需要下载

编写第一个自动化脚本

以火狐为例

//启动火狐浏览器

WebDriver driver = new FirefoxDriver();

driver.get("http://www.baidu.com/");

启动主流浏览器:firefox, chrome, IE

启动chrome浏览器

启动chrome需要chromedriver的驱动

下载地址:http://npm.taobao.org/mirrors/chromedriver/

根据chrome浏览器版本下载对应chromedriver

演示chrome版本是67,对应chromedriver如下

chromedriver配置

配置方法有两种,一种是配在环境变量里,这里直接在代码里指定路径

运行脚本如图

//启动谷歌浏览器

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Administrator\\Desktop\\testerbang\\work\\eclipse-workspace\\testerbang\\tools\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

driver.get("http://www.baidu.com/");

启动IE浏览器

启动IE需要DriverServer驱动,同样,版本号和Selenium的版本号一定要一致

下载地址:http://selenium-release.storage.googleapis.com/index.html

运行脚本如下

//启动ie浏览器

System.out.println("startiebrowser...");

System.setProperty("webdriver.ie.driver", "C:\\Users\\Administrator\\Desktop\\testerbang\\work\\eclipse-workspace\\testerbang\\tools\\IEDriverServer.exe");

WebDriver driver = newInternetExplorerDriver();

driver.get("http://www.baidu.com/");

System.out.println("startiebrowser succeed...");

配置IE浏览器

启动浏览器报错

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 stacktraceinformation)

针对windows 7上的IE7或者更高的版本,必须在IE选项设置的安全页中,4个区域的启用保护模式的勾选都去掉(或都勾上),即保持四个区域的保护模式是一致的

针对IE10和更高的版本,必须在IE选项设置中的高级页中,取消增强保护模式

启动浏览器报错

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 stacktraceinformation)

针对windows vista和windows 7上的IE7或者更高的版本,必须在IE选项设置的安全页中,4个区域的启用保护模式的勾选都去掉(或都勾上),即保持四个区域的保护模式是一致的

针对IE10和更高的版本,必须在IE选项设置中的高级页中,取消增强保护模式

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-07-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 测试邦 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Firefox及firebug的介绍
    • Firefox
      • firebug的介绍
      • 编写第一个自动化脚本
      • 启动主流浏览器:firefox, chrome, IE
        • 启动chrome浏览器
          • chromedriver配置
            • 启动IE浏览器
              • 配置IE浏览器
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档