Created
December 7, 2013 13:43
-
-
Save oiuww09fn/7841466 to your computer and use it in GitHub Desktop.
Selenium with python for chrome safari and opera.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from selenium import webdriver | |
a = webdriver.chrome.options.Options() | |
a.binary_location = None | |
driver = webdriver.Chrome() # Optional argument, if not specified will search path. | |
driver.get('http://www.google.com/xhtml') | |
time.sleep(5) # Let the user actually see something! | |
search_box = driver.find_element_by_name('q') | |
search_box.send_keys('ChromeDriver') | |
search_box.submit() | |
time.sleep(5) # Let the user actually see something! | |
driver.quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Please start remote server before run this file. | |
# java -jar selenium-server-standalone-2.31.0.jar | |
# from selenium import webdriver | |
# from selenium.webdriver.remote.command import Command | |
# from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | |
# | |
# browser = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.CHROME); | |
# | |
# browser.get("http://www.tudou.com/"); | |
# | |
# browser.find_element_by_css_selector("#email").send_keys("test") | |
# browser.find_element_by_css_selector("#pwd").send_keys("1234") | |
# | |
# browser.find_element_by_css_selector("input.lg_b").click() | |
# | |
# element = browser.find_element_by_css_selector("#myTudouNav") | |
# browser.execute(Command.MOVE_TO, {'element': element.id}) | |
# | |
# browser.find_element_by_xpath(".//*[@id='myTudouNav']/div/ul/li[12]/a").click() | |
# | |
# js = "$('.logo').css('border', '1px solid red');"; | |
# browser.execute_script(js) | |
# | |
# browser.close() | |
from selenium import webdriver | |
import time | |
browser_name = {'browserName': 'opera'} | |
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=browser_name) | |
time.sleep(2) | |
driver.get('http://www.baidu.com') | |
print driver.current_url | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment