PySe-006-Se-WebDriver 启动浏览器之三 - Safari

之前的文章讲述了通过 WebDriver 如何启动 Firefox、Chrome 浏览器,及其相应的 MacOX 环境配置,请各位小主们参阅以下链接:

既然是在 MacOX 中穿插学习 PySe,那怎么可能少了 Safari 浏览器呢,幸运的是 Selenium2 支持了 Safari 浏览器,下面就开始我们的 Selenium2 Safari 之旅吧。

一、Safari 环境配置

安装 Safari 浏览器插件: SafariDriver.safariextz

首先,若想启动 Safari 浏览器,WebDriver 同样需要安装 Safari 的 driver,

  1. 下载 SafariDriver.safariextz,selenium-release.storage.googleapis.com/2.46/SafariDriver.safariextz
  2. 下载好后,打开 Safari 浏览器,依次点击 Safari --> 偏好设置 --> 扩展
  3. 将 SafariDriver.safariextz 拖拽至 扩展页面,安装 SafariDriver.safariextz
  4. 启用 WebDriver

安装好 Safari WebDriver 扩展插件后,如下图所示

另外,也可以通过 selenium-server-standalone-2.46.0.jar 中获取相应版本的 SafariDriver.safariextz

通过执行命令:jar xf selenium-server-standalone-2.46.0.jar 可解压 jar 文件,过程中出现的 license 目录无法创建可忽略。

配置环境变量:SELENIUM_SERVER_JAR

将 selenium-server-standalone-2.46.0.jar 放置在一个空文件夹,例如:cp selenium-server-standalone-2.46.0.jar /Library/Selenium/selenium-server-standalone-2.46.0.jar

然后通过以下命令,添加环境变量 SELENIUM_SERVER_JAR

export SELENIUM_SERVER_JAR="/Library/Selenium/selenium-server-standalone-2.46.0.jar"

若未配置环境变量,则在执行测试脚本时,会有如下所示的错误信息,提示添加环境变量

Aaron-test:pyse aaron$ python pyse_demo_safari.py
Traceback (most recent call last):
  File "pyse_demo_safari.py", line 6, in <module>
    browser = webdriver.Safari()
  File "/Library/Python/2.7/site-packages/selenium/webdriver/safari/webdriver.py", line 54, in __init__
    ‘SELENIUM_SERVER_JAR‘")
Exception: No executable path given, please add one to Environment Variable                 ‘SELENIUM_SERVER_JAR‘
Aaron-test:pyse aaron$

二、编写示例脚本

启动 Safari 的自动化脚本的工作事项如下所示:

  1. 启动 Safari
  2. 打开 百度
  3. 输入搜索关键字 范丰平
  4. 点击 搜素 按钮
  5. 获取名称为 范丰平 - 博客园 的元素
  6. 输出元素 text 值
  7. 退出 Driver

相应的脚本 pyse_demo_safari.py 内容如下所示:

 1 #!/usr/local/bin/python
 2 # -*- coding: utf-8 -*-
 3
 4 from selenium import webdriver
 5 import time
 6
 7 # open safari
 8 safari = webdriver.Safari()
 9
10 safari.set_window_position(20, 100)
11 safari.set_window_size(1000, 700)
12
13 # navigate to baidu
14 safari.get("http://www.baidu.com/")
15
16 safari.implicitly_wait(4)
17
18 # get input key
19 txt_search_key = safari.find_element_by_id("kw")
20
21 # clear input and type key
22 txt_search_key.clear()
23 txt_search_key.send_keys(u"范丰平")
24
25 # get search and click
26 btn_search = safari.find_element_by_id("su")
27 btn_search.click()
28
29 safari.implicitly_wait(10)
30
31 # click link text
32 link = safari.find_element_by_partial_link_text(u"范丰平")
33
34 print link.text
35
36 time.sleep(5)
37
38 safari.close()
39
40 safari.quit()

三、执行脚本

进入命令行控制台,进入 pyse_demo_safari.py 所在目录,执行命令 python pyse_demo_safari.py,执行后出现了如下所示的错误,不知哪位大神可知原因,劳烦告知,非常感谢!

  1 Aaron-test:pyse aaron$ python pyse_demo_safari.py
  2 13:20:31.244 INFO - Launching a standalone Selenium Server
  3 13:20:31.275 INFO - Java: Oracle Corporation 25.40-b25
  4 13:20:31.275 INFO - OS: Mac OS X 10.10.2 x86_64
  5 13:20:31.284 INFO - v2.46.0, with Core v2.46.0. Built from revision 87c69e2
  6 13:20:31.359 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
  7 registration capabilities Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}] does not match the current platform MAC
  8 13:20:31.360 INFO - Driver class not found: com.opera.core.systems.OperaDriver
  9 13:20:31.360 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
 10 13:20:31.457 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:55186/wd/hub
 11 13:20:31.457 INFO - Selenium Server is up and running
 12 13:20:41.025 INFO - Executing: [new session: Capabilities [{browserName=safari, javascriptEnabled=true, version=, platform=ANY}]])
 13 13:20:41.033 INFO - Creating a new session for Capabilities [{browserName=safari, javascriptEnabled=true, version=, platform=ANY}]
 14 13:20:41.088 INFO - Server started on port 41255
 15 13:20:41.095 INFO - Launching Safari
 16 13:20:41.103 INFO - Waiting for SafariDriver to connect
 17 13:20:43.819 INFO - Connection opened
 18 13:20:43.838 INFO - Driver connected in 2735 ms
 19 13:20:43.876 INFO - Shutting down
 20 13:20:43.876 INFO - Closing connection
 21 13:20:43.877 INFO - Stopping Safari
 22 13:20:43.987 INFO - Stopping server
 23 13:20:43.987 INFO - Stopping server
 24 13:20:43.996 INFO - Shutdown complete
 25 13:20:43.997 WARN - Exception thrown
 26 java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
 27 Build info: version: ‘2.46.0‘, revision: ‘87c69e2‘, time: ‘2015-06-04 16:16:47‘
 28 System info: host: ‘aaron-test.local‘, ip: ‘127.0.0.1‘, os.name: ‘Mac OS X‘, os.arch: ‘x86_64‘, os.version: ‘10.10.2‘, java.version: ‘1.8.0_40‘
 29 Driver info: driver.version: unknown
 30     at java.util.concurrent.FutureTask.report(FutureTask.java:122)
 31     at java.util.concurrent.FutureTask.get(FutureTask.java:192)
 32     at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
 33     at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:119)
 34     at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
 35     at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:137)
 36     at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:58)
 37     at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
 38     at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
 39     at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:174)
 40     at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:202)
 41     at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:164)
 42     at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
 43     at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:130)
 44     at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
 45     at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
 46     at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
 47     at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
 48     at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
 49     at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
 50     at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
 51     at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
 52     at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
 53     at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
 54     at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
 55     at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
 56     at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
 57 Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
 58 Build info: version: ‘2.46.0‘, revision: ‘87c69e2‘, time: ‘2015-06-04 16:16:47‘
 59 System info: host: ‘aaron-test.local‘, ip: ‘127.0.0.1‘, os.name: ‘Mac OS X‘, os.arch: ‘x86_64‘, os.version: ‘10.10.2‘, java.version: ‘1.8.0_40‘
 60 Driver info: driver.version: unknown
 61     at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:95)
 62     at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:79)
 63     at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:62)
 64     at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
 65     at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
 66     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 67     at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
 68     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 69     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 70     at java.lang.Thread.run(Thread.java:745)
 71 Caused by: java.lang.reflect.InvocationTargetException
 72     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 73     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 74     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 75     at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
 76     at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:85)
 77     ... 9 more
 78 Caused by: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
 79 Build info: version: ‘2.46.0‘, revision: ‘87c69e2‘, time: ‘2015-06-04 16:16:47‘
 80 System info: host: ‘aaron-test.local‘, ip: ‘127.0.0.1‘, os.name: ‘Mac OS X‘, os.arch: ‘x86_64‘, os.version: ‘10.10.2‘, java.version: ‘1.8.0_40‘
 81 Driver info: driver.version: SafariDriver
 82     at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
 83     at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
 84     at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
 85     at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
 86     at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:58)
 87     at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:51)
 88     ... 14 more
 89 Caused by: java.lang.ClassCastException: com.google.gson.JsonObject cannot be cast to java.lang.String
 90     at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:111)
 91     at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:42)
 92     at org.openqa.selenium.safari.SafariDriverCommandExecutor.execute(SafariDriverCommandExecutor.java:191)
 93     at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
 94     ... 19 more
 95 13:20:44.001 WARN - Exception: com.google.gson.JsonObject cannot be cast to java.lang.String
 96 Traceback (most recent call last):
 97   File "pyse_demo_safari.py", line 8, in <module>
 98     browser = webdriver.Safari()
 99   File "/Library/Python/2.7/site-packages/selenium/webdriver/safari/webdriver.py", line 60, in __init__
100     desired_capabilities=desired_capabilities)
101   File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 87, in __init__
102     self.start_session(desired_capabilities, browser_profile)
103   File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 136, in start_session
104     ‘desiredCapabilities‘: desired_capabilities,
105   File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 196, in execute
106     self.error_handler.check_response(response)
107   File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 181, in check_response
108     raise exception_class(message, screen, stacktrace)
109 selenium.common.exceptions.WebDriverException: Message: com.google.gson.JsonObject cannot be cast to java.lang.String
110 Stacktrace:
111     at org.openqa.selenium.remote.JsonToBeanConverter.convert (JsonToBeanConverter.java:111)
112     at org.openqa.selenium.remote.JsonToBeanConverter.convert (JsonToBeanConverter.java:42)
113     at org.openqa.selenium.safari.SafariDriverCommandExecutor.execute (SafariDriverCommandExecutor.java:191)
114     at org.openqa.selenium.remote.RemoteWebDriver.execute (RemoteWebDriver.java:578)
115     at org.openqa.selenium.remote.RemoteWebDriver.startSession (RemoteWebDriver.java:242)
116     at org.openqa.selenium.remote.RemoteWebDriver.<init> (RemoteWebDriver.java:128)
117     at org.openqa.selenium.remote.RemoteWebDriver.<init> (RemoteWebDriver.java:141)
118     at org.openqa.selenium.safari.SafariDriver.<init> (SafariDriver.java:58)
119     at org.openqa.selenium.safari.SafariDriver.<init> (SafariDriver.java:51)
120     at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
121     at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
122     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
123     at java.lang.reflect.Constructor.newInstance (Constructor.java:422)
124     at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor (DefaultDriverProvider.java:85)
125     at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance (DefaultDriverProvider.java:79)
126     at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance (DefaultDriverFactory.java:62)
127     at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call (DefaultSession.java:222)
128     at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call (DefaultSession.java:1)
129     at java.util.concurrent.FutureTask.run (FutureTask.java:266)
130     at org.openqa.selenium.remote.server.DefaultSession$1.run (DefaultSession.java:176)
131     at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
132     at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
133     at java.lang.Thread.run (Thread.java:745)

Python + Selenium 启动 Safari 浏览器报错详细信息

对应的 Safari 浏览器版本如下所示:

解决办法:

1、更新 Safari 的插件 SafariDriver.safariextz 为 selenium-server-standalone-2.47.1.jar 中的 SafariDriver.safariextz

2、更新 selenium-server-standlone-2.46.0.jar 为 selenium-server-standalone-2.47.1.jar

3、更新 SELENIUM_SERVER_JAR 变量为 : /Library/Selenium/selenium-server-standalone-2.47.1.jar

4、重新执行脚本 python pyse_demo_safari.py,执行日志如下所示:

16:18:56.330 INFO - Launching a standalone Selenium Server
16:18:56.360 INFO - Java: Oracle Corporation 25.40-b25
16:18:56.361 INFO - OS: Mac OS X 10.10.2 x86_64
16:18:56.370 INFO - v2.47.1, with Core v2.47.1. Built from revision 411b314
16:18:56.429 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}] does not match the current platform MAC
16:18:56.429 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver registration is skipped:
registration capabilities Capabilities [{browserName=MicrosoftEdge, version=, platform=WINDOWS}] does not match the current platform MAC
16:18:56.429 INFO - Driver class not found: com.opera.core.systems.OperaDriver
16:18:56.429 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
16:18:56.488 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:57241/wd/hub
16:18:56.488 INFO - Selenium Server is up and running
16:19:06.330 INFO - Executing: [new session: Capabilities [{browserName=safari, javascriptEnabled=true, version=, platform=ANY}]])
16:19:06.338 INFO - Creating a new session for Capabilities [{browserName=safari, javascriptEnabled=true, version=, platform=ANY}]
16:19:06.394 INFO - Server started on port 39043
16:19:06.402 INFO - Launching Safari
16:19:06.410 INFO - Waiting for SafariDriver to connect
16:19:07.137 INFO - Connection opened
16:19:07.138 INFO - Driver connected in 728 ms
16:19:07.183 INFO - Done: [new session: Capabilities [{browserName=safari, javascriptEnabled=true, version=, platform=ANY}]]
16:19:07.195 INFO - Executing: [set window position])
16:19:07.211 INFO - Done: [set window position]
16:19:07.215 INFO - Executing: [set window size])
16:19:07.744 INFO - Done: [set window size]
16:19:07.748 INFO - Executing: [get: http://www.baidu.com/])
16:19:09.139 INFO - Done: [get: http://www.baidu.com/]
16:19:09.144 INFO - Executing: [implicitly wait: 4000])
16:19:09.150 INFO - Done: [implicitly wait: 4000]
16:19:09.155 INFO - Executing: [find element: By.id: kw])
16:19:09.252 INFO - Done: [find element: By.id: kw]
16:19:09.255 INFO - Executing: [clear: 0 [[SafariDriver: safari on MAC (null)] -> id: kw]])
16:19:09.261 INFO - Done: [clear: 0 [[SafariDriver: safari on MAC (null)] -> id: kw]]
16:19:09.265 INFO - Executing: [send keys: 0 [[SafariDriver: safari on MAC (null)] -> id: kw], [范, 丰, 平]])
16:19:09.332 INFO - Done: [send keys: 0 [[SafariDriver: safari on MAC (null)] -> id: kw], [范, 丰, 平]]
16:19:09.335 INFO - Executing: [find element: By.id: su])
16:19:09.339 INFO - Done: [find element: By.id: su]
16:19:09.342 INFO - Executing: [click: 1 [[SafariDriver: safari on MAC (null)] -> id: su]])
16:19:09.361 INFO - Done: [click: 1 [[SafariDriver: safari on MAC (null)] -> id: su]]
16:19:09.364 INFO - Executing: [implicitly wait: 10000])
16:19:09.384 INFO - Done: [implicitly wait: 10000]
16:19:09.390 INFO - Executing: [find element: By.partialLinkText: 范丰平])
16:19:09.843 INFO - Done: [find element: By.partialLinkText: 范丰平]
16:19:09.846 INFO - Executing: [get text: 2 [[SafariDriver: safari on MAC (null)] -> partial link text: 范丰平]])
16:19:09.851 INFO - Done: [get text: 2 [[SafariDriver: safari on MAC (null)] -> partial link text: 范丰平]]
范丰平 - 博客园
16:19:14.855 INFO - Executing: [close window])
16:19:14.864 INFO - Done: [close window]
16:19:14.867 INFO - Executing: [delete session: 5109aef4-10ad-4602-91e7-17be071473a8])
16:19:14.867 INFO - Shutting down
16:19:14.867 INFO - Closing connection
16:19:14.868 INFO - Stopping Safari
16:19:14.924 INFO - Stopping server
16:19:14.924 INFO - Stopping server
16:19:14.929 INFO - Shutdown complete
16:19:14.929 INFO - Done: [delete session: 5109aef4-10ad-4602-91e7-17be071473a8]

执行结果如图所示:

至此, PySe-006-Se-WebDriver 启动浏览器之三 - Safari 顺利完结,希望此文能够给初学 Python + Selenium2 的您一份参考。

最后,非常感谢亲的驻足,希望此文能对亲有所帮助。热烈欢迎亲一起探讨,共同进步。非常感谢! ^_^

时间: 2024-10-08 21:14:57

PySe-006-Se-WebDriver 启动浏览器之三 - Safari的相关文章

【转】Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&amp;加载插件

基本读踩过的坑,泪流满面··· 本文主要记录下在使用selenium2/webdriver时启动各种浏览器的方法.以及如何加载插件.定制浏览器信息(设置profile)等 环境搭建可参考我的另一篇文章:http://www.cnblogs.com/puresoul/p/3483055.html 一.Driver下载地址: http://docs.seleniumhq.org/download/ 二.启动firefox浏览器(不需要下载驱动,原生支持) 1.firefox安装在默认路径下: 1 /

WebDriver - 设置浏览器启动语言

作者: Max.Bai 时间: 2015/06 WebDriver - 设置浏览器启动语言 有时候开启浏览器需要特别的语言版本,比如,英文的,中文的. 测试时候发现,机器默认启动的是系统语言对应的浏览器,我们的被测网站的中文的,而系统是英文的,开启的浏览器就是英文的,提交的某些数据按照en-US的格式提交了,导致数据报错,那么我们就需要设置浏览器启动语言. 1. Firefox Firefox 我们可以通过FirefoxProfile 来解决这个问题. FirefoxProfile ffpf =

Selenium2(WebDriver)总结(一)---启动浏览器、设置profile&amp;加载插件

本文主要记录下在使用selenium2/webdriver时启动各种浏览器的方法.以及如何加载插件.定制浏览器信息(设置profile)等 环境搭建可参考我的另一篇文章:http://www.cnblogs.com/puresoul/p/3483055.html 一.Driver下载地址: http://docs.seleniumhq.org/download/ 二.启动firefox浏览器(不需要下载驱动,原生支持) 1.firefox安装在默认路径下: 1 //启动默认安装路径下的ff 2

Python+selenium+eclipse执行web自动化(二)启动浏览器

一.浏览器兼容性 当前selenium 2.0支持的浏览器 从selenium的__init__文件中可以查看到,我当前使用的selenium版本是2.53.2 从selenium的Webdriver模块查看__init__文件,可以看到以下代码: from .firefox.webdriver import WebDriver as Firefoxfrom .firefox.firefox_profile import FirefoxProfilefrom .chrome.webdriver

设置Webdriver启动chrome为默认用户的配置信息

Webdriver 启动Chrome浏览器时,默认是打开一个新用户,而非默认用户,即新用户没有我们安装扩展程序.但在实际应用中,我们会需要 默认用户安装的一些扩展程序,比如对于某些js或者css样式,需要代理才能访问成功,使用默认用户就显得尤为重要(因为你不可能在新用户在安装扩展程序再继续测试). 如图: a)默认用户的扩展: 在锁定chrome的任务栏打开的状态: b) WebDriver打开的新用户的扩展: 在锁定chrome的任务栏打开的状态: ----------------------

【Selenium2+Java自动化(2)】-启动浏览器

1.常用的浏览器有IE,Chrome,FireFox:其中IE和Chrome浏览器需要下载驱动程序,才能启动浏览器.注意驱动程序有32和64位的区别.如何查看本机的浏览器版本和位数:(1)IE:打开IE浏览器,然后点击右上角的"齿轮"设置图标:在下拉菜单中,点击"关于Internet Explorer":这时会弹出一个窗口分别显示IE浏览器的版本及位数:窗口中显示的就是IE浏览器的版本及位数,其中32位IE 没有位数显示,而64位IE浏览器则显示 64-bit .

启动浏览器笔记

一,准备文件 : 准备两个包在eclipse中files和lib Lib下面 log4j-1.2.17.jar selenium-server-standalone-2.44.0.jar files文件: 二,代码 代码: package webdriver; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver.Navigation; import org.openqa.selenium.chrom

PySe-003-Se-WebDriver 启动浏览器之一 - Firefox

此文主要演示 MacOX 下 WebDriver 启动 Firefox 浏览器,因 WebDriver 对 Firefox 浏览器是原生支持的,因而无需像启动其他浏览器一样需要相对应的 driver. 启动 firefox 浏览器的代码非常的简单,直接上码了,敬请参阅.操作内容如下所示: 启动 firefox 浏览器 打开网页 http://www.cnblogs.com/fengpingfan/ (个人的博客地址链接) 1 #!/usr/local/bin/python 2 # -*- cod

基于Selenium2+Java的PC自动化(2) - 启动浏览器

一.准备工作 我们常用的浏览器主要有三个:chrome.Firefox.IE:其中chrome 和 IE 需要下载驱动程序,才能启动浏览器,注意驱动程序有32位和64位两种. 另外:如何查看本机的浏览器版本:(1)IE:查看安装路径,如果是安装在Program Files (x86)中,表示32位.如果安装在Program Files 中,表示64位:(2)Chrome:在谷歌浏览器地址栏输入:chrome:version,然后回车,会有详细显示: QQ图片20161115202252.png1