您的位置:首页 > 编程语言 > Python开发

Example code for using the Selenium 2 Python bindings. — Gist

2012-07-16 19:52 666 查看
Example code for using the Selenium 2 Python bindings. — Gist

# To install the Python client library:# pip install -U selenium# Import the Selenium 2 namespace (aka "webdriver")from selenium import webdriver# iPhonedriver = webdriver.Remote(browser_name="iphone", command_executor='http://172.24.101.36:3001/hub')# Androiddriver = webdriver.Remote(browser_name="android", command_executor='http://127.0.0.1:8080/hub')# Google Chrome driver = webdriver.Chrome()# Firefox driver = webdriver.Firefox()# ------------------------------# The actual test scenario: Test the codepad.org code execution service.# Go to codepad.orgdriver.get('http://codepad.org')# Select the Python language optionpython_link = driver.find_elements_by_xpath("//input[@name='lang' and @value='Python']")[0]python_link.click()# 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')submit_button.click()# Make this an actual test. Isn't Python beautiful?assert "Hello, World!" in driver.get_page_source()# Close the browser!driver.quit()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐