Python 3.4:Chromedrive,IEDriverServer,geckoDriver,
import sys;import time;import os;#from huoche import PythonTickt;from splinter.browser import Browser;#from splinter.driver.webdriver import BaseWebDriver, WebDriverElement;#from splinter import Browser;from selenium import webdriver;from selenium.webdriver.common.keys import Keys;import selenium.webdriver.chrome.service as service;import traceback;from selenium.webdriver import Chrome;from selenium.webdriver.chrome.options import Options;from pyvirtualdisplay import Display;'''firepath="C:/Program Files/Mozilla Firefox/";browser = webdriver.Firefox(firepath)browser.get('http://www.yahoo.com')assert 'Yahoo' in browser.titleelem = browser.find_element_by_name('p') # Find the search boxelem.send_keys('seleniumhq' + Keys.RETURN)browser.quit()'''# 瀏覽器的驅動 chrome http://chromedriver.storage.googleapis.com/index.html# https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver #https://github.com/mozilla/geckodriver/releases #Firefox驅動 geckodriver#http://selenium-release.storage.googleapis.com/index.html# http://selenium-release.storage.googleapis.com/index.html?path=3.8/ #IE驅動#https://sites.google.com/a/chromium.org/chromedriver/home#https://sites.google.com/a/chromium.org/chromedriver/getting-started#https://github.com/SeleniumHQ/selenium/tree/master/py#http://www.techbeamers.com/selenium-webdriver-python-tutorial/#service = service.Service('C:/Program Files (x86)/Google/Chrome/Application/chrome.exe')#service.start()#capabilities = {'chrome.binary': 'C:/Program Files (x86)/Google/Chrome/Application'}#driver = webdriver.Remote(service.service_url, capabilities)#driver.get('http://www.google.com/xhtml');#time.sleep(5) # Let the user actually see something!#driver.quit()executable_path = {'executable_path':'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'};# **executable_path #開啟了還是有異常# http://splinter.readthedocs.io/en/latest/api/driver-and-element-api.html #splinter.browser.Browser(driver_name='firefox', *args, **kwargs) path='C:/Program Files (x86)/Google/Chrome/Application/';url = "https://kyfw.12306.cn/otn/leftTicket/init"; #huoche=huoche();chrome#driver = webdriver.Firefox();#driver.get("http://www.google.com/");# create a new Firefox session'''driver = webdriver.Firefox(firepath)driver.implicitly_wait(30)driver.maximize_window()# navigate to the application home pagedriver.get("http://www.google.com")# get the search textboxsearch_field = driver.find_element_by_id("lst-ib")search_field.clear()# enter search keyword and submitsearch_field.send_keys("Selenium WebDriver Interview questions")search_field.submit()# get the list of elements which are displayed after the search# currently on result page using find_elements_by_class_name methodlists= driver.find_elements_by_class_name("_Rm")# get the number of elements foundprint ("Found" + str(len(lists)) + "searches:");# iterate through each element and print the text that is# name of the searchi=0for listitem in lists: print (listitem) i=i+1 if(i>10): break# close the browser windowdriver.quit()'''# get the path of IEDriverServer# https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriveriepath="C:/Python34/IEDriverServer.exe"dir = os.path.dirname(__file__)# 當前檔案的地址ie_driver_path =iepath;# dir + "\IEDriverServer.exe"# create a new Internet Explorer sessiondriver = webdriver.Ie(ie_driver_path)driver.implicitly_wait(30)driver.maximize_window()# navigate to the application home pagedriver.get("http://www.google.com")# get the search textboxsearch_field = driver.find_element_by_name("q")# enter search keyword and submitsearch_field.send_keys("Selenium WebDriver Interview questions")search_field.submit()# get the list of elements which are displayed after the search# currently on result page using find_elements_by_class_name methodlists= driver.find_elements_by_class_name("r")# get the number of elements foundprint ("Found" + str(len(lists)) + " searches:")# iterate through each element and print the text that is# name of the searchi=0for listitem in lists: print (listitem) i=i+1 if(i>10): break# close the browser windowdriver.quit()'''# get the path of ChromeDriverServerdir = os.path.dirname(__file__)chrome_driver_path = dir + "\chromedriver.exe"# create a new Chrome sessiondriver = webdriver.Chrome(chrome_driver_path)driver.implicitly_wait(30)driver.maximize_window()# navigate to the application home pagedriver.get("http://www.google.com")# get the search textboxsearch_field = driver.find_element_by_name("q")# enter search keyword and submitsearch_field.send_keys("Selenium WebDriver Interview questions")search_field.submit()# get the list of elements which are displayed after the search# currently on result page using find_elements_by_class_name methodlists= driver.find_elements_by_class_name("r")# get the number of elements foundprint ("Found" + str(len(lists)) + " searches:")# iterate through each element and print the text that is# name of the searchi=0for listitem in lists: print (listitem) i=i+1 if(i>10): break# close the browser windowdriver.quit()'''browser=webdriver.Chrome()#first tabbrowser.get('http:/reddit.com')#second tabbrowser.execute_script("window.open('about:blank', 'tab2');")browser.switch_to.window("tab2")browser.get('http://bing.com')#Browser("chrome",**executable_path, fullscreen=True);#size=driver.manage().window().setSize(new Dimension(1024,768));#options = Options();#options.add_argument('--lang=en-us');#global browser;#browser = BaseWebDriver();#browser.driver = Chrome(chrome_options=options);chrome_options = Options()chrome_options.add_argument("--headless")chrome_options.add_argument("--window-size=1366,768")# https://sites.google.com/a/chromium.org/chromedriver/downloadschrome_driver = 'C:/Program Files (x86)/Google/Chrome/Application/'driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=chrome_driver)driver.get("https://www.wikipedia.org/")english_link = driver.find_element_by_css_selector("#js-link-box-en")english_link.click()d = Display(visible=0, size=(800, 600));d.start();chrome_options = ChromeOptions()chrome_options.add_argument('disable-setuid-sandbox');b = Browser('chrome');b.visit('http://www.google.com');b.quit();d.stop();options = Options()options.add_argument("window-size=1,1");browser = BaseWebDriver()browser.driver = Chrome(chrome_options=options)browser.visit('https://www.google.com')