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')

  

Python 3.4:Chromedrive,IEDriverServer,geckoDriver的更多相关文章

  1. 【python驱动】python进行selenium测试时GeckoDriver放在什么地方?

    背景:用python进行selenium 关于b/s架构的测试,需要配置驱动否则程序无法执行 情况1:windows下放置GeckoDriver 步骤1:下载驱动 GeckoDriver下载地址fir ...

  2. python自动化测试学习目录

    一.python学习目录 <1> ----python驱动 [python驱动]python进行selenium测试时GeckoDriver放在什么地方? python下浏览器静默运行驱动 ...

  3. 使用Python+selenium实现第一个自动化测试脚本

    原blog 一,安装Python. python官方下载地址:https://www.python.org/downloads/ 安装后点击开始菜单,在菜单最上面能找到IDLE. IDLE是pytho ...

  4. python爬虫——selenium+firefox使用代理

    本文中的知识点: python selenium库安装 firefox geckodriver的下载与安装 selenium+firefox使用代理 进阶学习 搭建开发环境: selenium库 fi ...

  5. python中使用selenium调用Firefox缺少geckodriver解决方法

    from selenium import webdriver driver=webdriver.Firefox() 会报错 解决方法: 因为缺少geckodriver.exe,先到https://gi ...

  6. selenium chromedriver geckodriver iedriverserver下载

    chromedriver与chrome的的对应版整理: chromedriver版本 chrome版本 v2.9 v31-v34 v2.10 v33-v36 v2.11 v36-v40 v2.12 v ...

  7. 关于 chromedriver、IEDriverServer、geckodriver 驱动器的几项注意点

    1. 下载 chromedriver 和 IEDriverServer 时,都没有对应的 win64 版本,只能选择 win32,也一样可以: 2. 下载的 IEDriverServer 的版本号和S ...

  8. GeckoDriver+Selenium+Python的安装和使用

    如果没有安装GeckoDriver会提示: selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executab ...

  9. 在Centos7上安装Python+Selenium+Firefox+Geckodriver

    1.事先准备好Centos7的系统 Centos系统是CentOS Linux release 7.4.1708 (Core) 查看Centos内核版本命令cat /etc/centos-releas ...

随机推荐

  1. vue keep-alive解决关闭标签动态缓存问题

    直接上代码: <keep-alive :include='topNavMentNames'> <router-view ></router-view> </k ...

  2. jquery中$().each() 和$.each()

    // 形参1: 当前的下标 // 形参2: 当前的dom节点元素 $('#div1').find('div').each(function (i, item) { // this === item 当 ...

  3. Linux pwn入门教程(1)——栈溢出基础

    作者:Tangerine@SAINTSEC 原文来自:https://bbs.ichunqiu.com/thread-42241-1-1.html 0×00 函数的进入与返回 要想理解栈溢出,首先必须 ...

  4. CentOS 解决vim乱码问题

    今天在服务器安装了任务调度工具(TaskCTL) 发现是乱码的,看了官方文档说的办法也没有处理成功,可能由于他们已经有一段时间没有维护这个版本了.(以前提供的免费版本) 后来发现CentOS的Vim的 ...

  5. Java异步执行多个HTTP请求的例子(需要apache http类库)

    直接上代码 package org.jivesoftware.spark.util; import java.io.IOException; import java.util.concurrent.C ...

  6. Spark Graphx

    Graphx    概述        Spark GraphX是一个分布式图处理框架,它是基于Spark平台提供对图计算和图挖掘简洁易用的而丰富的接口,极大的方便了对分布式图处理的需求.       ...

  7. CentOS 6.5静态IP的设置(NAT和桥接联网方式都适用)

    不多说,直接上干货! 为了方便,用Xshell来.并将IP设置为静态的.因为,在CentOS里,若不对其IP进行静态设置的话,则每次开机,其IP都是动态变化的,这样会给后续工作带来麻烦.为此,我们需将 ...

  8. 从零开始学 Web 之 HTML5(二)表单,多媒体新增内容,新增获取操作元素,自定义属性

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...

  9. MongoDB 日志切割三种方式

    MongoDB 日志切割 ​ MongoDB 默认是不会进行切割日志的,除非我们配置了 logRotate = rename,并且重启 MongoDB 服务,才会进行切割日志的,那么为了避免实际中我们 ...

  10. SpringMVC入门学习(二)

    SpringMVC入门学习(二) ssm框架 springMVC  在上一篇博客中,我简单介绍了一下SpringMVC的环境配置,和简单的使用,今天我们将进一步的学习下Springmvc的操作. mo ...