Python 3.4:Chromedrive,IEDriverServer,geckoDr…

2018-06-18 00:49:58来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

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.title
elem = browser.find_element_by_name('p')  # Find the search box
elem.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 page
driver.get("http://www.google.com")

# get the search textbox
search_field = driver.find_element_by_id("lst-ib")
search_field.clear()

# enter search keyword and submit
search_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  method
lists= driver.find_elements_by_class_name("_Rm")

# get the number of elements found
print ("Found" + str(len(lists)) + "searches:");

# iterate through each element and print the text that is
# name of the search

i=0
for listitem in lists:
   print (listitem)
   i=i+1
   if(i>10):
      break

# close the browser window
driver.quit()

'''
# get the path of IEDriverServer
# https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
iepath="C:/Python34/IEDriverServer.exe"
dir = os.path.dirname(__file__)# 当前文件的地址
ie_driver_path =iepath;# dir + "\IEDriverServer.exe"

# create a new Internet Explorer session
driver = webdriver.Ie(ie_driver_path)
driver.implicitly_wait(30)
driver.maximize_window()

# navigate to the application home page
driver.get("http://www.google.com")

# get the search textbox
search_field = driver.find_element_by_name("q")

# enter search keyword and submit
search_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  method
lists= driver.find_elements_by_class_name("r")

# get the number of elements found
print ("Found" + str(len(lists)) + " searches:")

# iterate through each element and print the text that is
# name of the search

i=0
for listitem in lists:
   print (listitem)
   i=i+1
   if(i>10):
      break

# close the browser window
driver.quit()

'''
# get the path of ChromeDriverServer
dir = os.path.dirname(__file__)
chrome_driver_path = dir + "\chromedriver.exe"

# create a new Chrome session
driver = webdriver.Chrome(chrome_driver_path)
driver.implicitly_wait(30)
driver.maximize_window()

# navigate to the application home page
driver.get("http://www.google.com")

# get the search textbox
search_field = driver.find_element_by_name("q")

# enter search keyword and submit
search_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  method
lists= driver.find_elements_by_class_name("r")

# get the number of elements found
print ("Found" + str(len(lists)) + " searches:")

# iterate through each element and print the text that is
# name of the search

i=0
for listitem in lists:
   print (listitem)
   i=i+1
   if(i>10):
      break

# close the browser window
driver.quit()
'''
browser=webdriver.Chrome()

#first tab
browser.get('http:/reddit.com')

#second tab
browser.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/downloads
chrome_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')

  

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Python中多重装饰器执行顺序(由下至上)

下一篇:029异常处理