|# To install the Python client library:|
|# pip install -U selenium|
|# Import the Selenium 2 namespace (aka "webdriver")|
|from selenium import webdriver|
|driver = webdriver.Remote(browser_name="iphone", command_executor='http://172.24.101.36:3001/hub')|
|driver = webdriver.Remote(browser_name="android", command_executor='http://127.0.0.1:8080/hub')|
|# Google Chrome|
|driver = webdriver.Chrome()|
|driver = webdriver.Firefox()|
|# The actual test scenario: Test the codepad.org code execution service.|
|# Go to codepad.org|
|# Select the Python language option|
|python_link = driver.find_elements_by_xpath("//input[@name='lang' and @value='Python']")|
|# Enter some text!|
|text_area = driver.find_element_by_id('textarea')|
|text_area.send_keys("print 'Hello,' + ' World!'")|
|# Submit the form!|
|submit_button = driver.find_element_by_name('submit')|
|# Make this an actual test. Isn't Python beautiful?|
|assert "Hello, World!" in driver.get_page_source()|
|# Close the browser!|
You can download the latest Python client from http://pypi.python.org/pypi/selenium. In Windows, at a command prompt in a terminal window try: "pip.exe install -U selenium" or "easy_install.exe install -U selenium". If you have trouble, google for how to install Pip or Easy Install.
Running Python 2.6.1 I am receiving the following error:
Any help would be greatly appreciated...
I am on a network behind a proxy. When i run this script, i get a new instance of Firefox with no proxy configured, that obviously fails to connect to any external site. I tried setting http_proxy env variable from shell but that didn't work. On the WebDriver FAQ on code.google.com, i found this Java code:
Proxy proxy = new Proxy();
// We use firefox as an example here.
// You could use any webdriver implementation here
How do i translate this to Python?
I gotta say ... I REALLY appreciated stumbling onto this! Thank you!!
I was facing a need to use Selenium on one project and a need to start learning Python for another. Doing both together seemed like a good idea, but I figured I'd need several days to figure out how to do it. Bingo! You got me up and running in 10 minutes! Great!
one small thing though -- "AttributeError: 'WebDriver' object has no attribute 'get_page_source'"
After a quick Google around, I found that this works, instead -- assert "Hello, World!" in driver.page_source
Worked fine for Chrome and Firefox,
Hi.. When i am trying to execute this script, i am getting error :
How to get over from this error???
I made several changes to make the code from GitHub run (on Ubuntu/FireFox).
Updated the code as I got error with the above example due to change in element name.
With the PhantomJS WebDriver being deprecated nowadays, it's handy to know how to use the Chrome WebDriver headless.
Here's how to do that:
from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument('headless') driver = webdriver.Chrome(chrome_options=options)