开发者

How can I disable web security in selenium through Python?

Apparently it's common for google-chrome to get this: http://jira.openqa.org/browse/SRC-740

The key is to start it without secur开发者_开发问答ity enabled. To disable security,

"--disable-web-security",

I'm having trouble wondering how to actually specify these command line arguments, though, so it fails on the open invocation here:

from selenium import selenium

sel = selenium('localhost', 4444, '*googlechrome', 'http://www.google.com/')
sel.start()
sel.open('/')

Here's how I start the selenium server:

shogun@box:~$ java -jar selenium-server-standalone-2.0b3.jar


To get this to work, I had to create an external script to wrap the chrome browser. Place a script somewhere your Selenium server can reach it (mine is at ~/bin/startchrome, and chmod it executable:

#!/bin/sh
# chrome expects to be run from the .app dir, so cd into it
# (the spaces in the path are a Mac thing)
cd /Applications/Google\ Chrome.app
exec ./Contents/MacOS/Google\ Chrome --disable-security $*

Then in your Python code, do this:

from selenium import selenium

browser = '*googlechrome /Users/pat/bin/startchrome'
sel = selenium('localhost', 4444, browser, 'http://www.google.com')
sel.start()
sel.open('/')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜