2
我正在嘗試使用Safari WebDriver,並且我按照說明here來構建Safari驅動程序,但現在我不知道如何導入它並在我的代碼中使用它。如何使用Selenium Safari Webdriver
我使用python在Mac OSX
我正在嘗試使用Safari WebDriver,並且我按照說明here來構建Safari驅動程序,但現在我不知道如何導入它並在我的代碼中使用它。如何使用Selenium Safari Webdriver
我使用python在Mac OSX
使用Python 2.7.5和Python模塊硒(2.41.0)。
這個例子打開Safari瀏覽器和做我的競標:
# -*- 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()
但這裏是出現在終端,當我運行它:
$ 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 [email protected]
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 [email protected]
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文件中記錄日誌我很想知道如何。