如何使用Selenium Safari Webdriver [英] How to use Selenium Safari Webdriver

查看:94
本文介绍了如何使用Selenium Safari Webdriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Safari WebDriver,并且按照说明此处来构建Safari驱动程序,但是现在我不知道如何导入它并在我的代码中使用它.

I'm trying to use Safari WebDriver, and I followed the instructions here to build a Safari Driver, but now I don't know how to import it and use it in my code.

我在Mac OSX上使用python

I'm using python on Mac OSX

推荐答案

使用Python 2.7.5和python模块硒(2.41.0).

Using Python 2.7.5 and python module selenium (2.41.0).

此示例打开Safari浏览器并进行出价:

This example opens a Safari browser and does my bidding:

# -*- coding: utf-8 -*-

print '''
Python Selenium Safari Example
'''

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import os

# path to selenium server standalone jar, downloaded here:
# http://docs.seleniumhq.org/download/
# or a direct url:
# http://selenium-release.storage.googleapis.com/2.41/selenium-server-standalone-2.41.0.jar
os.environ["SELENIUM_SERVER_JAR"] = "selenium-server-standalone-2.41.0.jar"
# note: I've put this jar file in the same folder as this python file

browser = webdriver.Safari()

# makes the browser wait if it can't find an element
browser.implicitly_wait(10)

browser.get("http://google.com/")

search_input = browser.find_element_by_css_selector("#gbqfq")
search_input.send_keys("python SELENIUM_SERVER_JAR turn logging off")
search_input.send_keys(Keys.RETURN)

raw_input("Press Enter to close...")

browser.quit()

但是这是我运行终端时出现的内容:

but here is what appears in the terminal when I run it:

$ python selenium_safari_example.py

Python Selenium Safari Example

May 27, 2014 4:24:17 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
16:24:17.918 INFO - Java: Apple Inc. 20.65-b04-462
16:24:17.918 INFO - OS: Mac OS X 10.7.5 x86_64
16:24:17.975 INFO - v2.41.0, with Core v2.41.0. Built from revision 3192d8a
16:24:18.418 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration     capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not     match with current platform: MAC
16:24:18.597 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:61893/wd/hub
16:24:18.598 INFO - Version Jetty/5.1.x
16:24:18.599 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
16:24:18.600 INFO - Started HttpContext[/selenium-server,/selenium-server]
16:24:18.600 INFO - Started HttpContext[/,/]
16:24:18.724 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@75e845c2
16:24:18.724 INFO - Started HttpContext[/wd,/wd]
16:24:18.732 INFO - Started SocketListener on 0.0.0.0:61893
16:24:18.732 INFO - Started org.openqa.jetty.jetty.Server@1ac88440
16:24:27.335 INFO - Executing: [new session: Capabilities [{platform=ANY, javascriptEnabled=true, browserName=safari,     version=}]] at URL: /session)
16:24:27.351 INFO - Creating a new session for Capabilities [{platform=ANY, javascriptEnabled=true, browserName=safari,     version=}]
16:24:27.580 INFO - Server started on port 1988
16:24:27.772 INFO - Launching Safari
16:24:27.928 INFO - Waiting for SafariDriver to connect
16:24:39.589 INFO - Connection opened
16:24:39.610 INFO - Driver connected in 11681 ms
16:24:39.813 INFO - Done: /session
16:24:39.917 INFO - Executing: [implicitly wait: 10000] at URL: /session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea/timeouts/    implicit_wait)
16:24:39.962 INFO - Done: /session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea/timeouts/implicit_wait
16:24:39.967 INFO - Executing: [get: http://google.com/] at URL: /session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea/url)
16:24:47.853 INFO - Done: /session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea/url
16:24:47.860 INFO - Executing: [find element: By.selector: #gbqfq] at URL: /session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea/    element)
16:24:48.372 INFO - Done: /session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea/element
16:24:48.382 INFO - Executing: [send keys: 0 [[SafariDriver: safari on MAC (null)] -> css selector: #gbqfq], [p, y, t, h, o,     n,  , S, E, L, E, N, I, U, M, _, S, E, R, V, E, R, _, J, A, R,  , t, u, r, n,  , l, o, g, g, i, n, g,  , o, f, f]] at URL: /    session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea/element/0/value)
16:24:48.537 INFO - Done: /session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea/element/0/value
Press Enter to close...
16:24:48.543 INFO - Executing: [send keys: 0 [[SafariDriver: safari on MAC (null)] -> css selector: #gbqfq], [?]] at URL: /    session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea/element/0/value)
16:24:49.113 INFO - Done: /session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea/element/0/value
16:24:59.122 INFO - Executing: [delete session: 24ca27ce-7f06-4d16-ab8f-3d7376b01eea] at URL: /session/24ca27ce-7f06-4d16-    ab8f-3d7376b01eea)
16:24:59.123 INFO - Shutting down
16:24:59.123 INFO - Closing connection
16:24:59.124 INFO - Stopping Safari
16:24:59.333 INFO - Stopping server
16:24:59.333 INFO - Stopping server
16:24:59.382 INFO - Uninstalling extensions
16:24:59.383 INFO - Shutdown complete
16:24:59.385 INFO - Done: /session/24ca27ce-7f06-4d16-ab8f-3d7376b01eea
$

如果有人知道您是否能够通过python调用禁用jar文件的日志记录,那么我很想知道.

If someone knows if you're able to disable logging from the jar file through a python call I'd love to know how.

这篇关于如何使用Selenium Safari Webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆