描述

本文主要是针对Chrome 62 , firefox57 ,和IE11 三个版本的操作。相关的driver 。可点击以下链接。所有的driver 建议放在浏览器的目录下,本文中所有的driver都放置在对应的浏览器根目录下。

https://files.cnblogs.com/files/linxinmeng/IE11_win10_3.5.zip

https://files.cnblogs.com/files/linxinmeng/Firefox57_win10_java1.8.zip

https://files.cnblogs.com/files/linxinmeng/chromedriver_X64_Chrome62.zip

注意事项

IE浏览器需要对安全进行设置 。以及【设置】中的缩放必须是100%。

  1. package 票务系统前台;
  2.  
  3. import java.util.concurrent.TimeUnit;
  4.  
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.chrome.ChromeDriver;
  7. import org.openqa.selenium.chrome.ChromeOptions;
  8. import org.openqa.selenium.firefox.FirefoxDriver;
  9. import org.openqa.selenium.firefox.FirefoxOptions;
  10. import org.openqa.selenium.firefox.FirefoxProfile;
  11. import org.openqa.selenium.firefox.internal.ProfilesIni;
  12. import org.openqa.selenium.ie.InternetExplorerDriver;
  13. import org.openqa.selenium.remote.DesiredCapabilities;
  14.  
  15. public class 浏览器操作 {
  16. static WebDriver driver;
  17.  
  18. public static void main(String[] args) {
  19. // IE_open(driver);
  20. // firefox_Open1(driver);
  21. chrome_Open(driver);
  22. }
  23.  
  24. public static WebDriver chrome_Open(WebDriver driver) {
  25. System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver_X64\\chromedriver_X64.exe");
  26. ChromeOptions Options = new ChromeOptions();
  27. Options.addArguments("user-data-dir=C:\\Users\\linxinmeng\\AppData\\Local\\Google\\Chrome\\User Data");
  28. driver = new ChromeDriver(Options);
  29. driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);
  30.  
  31. driver.get("http://www.baidu.com");
  32. return driver;
  33. }
  34.  
  35. public static WebDriver IE_open(WebDriver driver) {
  36. System.setProperty("webdriver.ie.driver", "C:\\Program Files (x86)\\Internet Explorer\\IEDriverServer.exe");
  37. driver = new InternetExplorerDriver();
  38. driver.get("http://www.baidu.com");
  39. return driver;
  40.  
  41. }
  42.  
  43. public static WebDriver firefox_Open1(WebDriver driver) {
  44.  
  45. System.setProperty("webdriver.firefox.bin", "D:\\软件应用宝\\Mozilla Firefox\\firefox.exe");
  46. System.setProperty("webdriver.gecko.driver", "D:\\软件应用宝\\Mozilla Firefox\\geckodriver.exe");
  47. FirefoxOptions ffo = new FirefoxOptions();
  48. driver = new FirefoxDriver(ffo);
  49. driver.get("https://www.baidu.com");
  50. return driver;
  51. }
  52.  
  53. }

selenium webdriver操作各浏览器的更多相关文章

  1. Selenium webdriver 操作chrome 浏览器

    Step1: 下载chromedriver. 下载路径: http://chromedriver.storage.googleapis.com/index.html 选择一个合适的下载即可.我下载的是 ...

  2. Selenium webdriver 操作IE浏览器

    V1.0版本:直接新建WebDriver使用 import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetE ...

  3. Selenium WebDriver使用IE浏览器

    摘:http://www.cnblogs.com/dream0577/archive/2012/10/07/2714579.html /**       用IE驱动,1.先到官网下载IEDriverS ...

  4. selenium webdriver启动Chrome浏览器后无法输入网址的解决办法

    通过selenium webdriver启动Chrome浏览器,脚本如下: from selenium import webdriver browser = webdriver.Chrome() br ...

  5. selenium webdriver启动IE浏览器失败的解决办法

    通过selenium webdriver启动IE浏览器失败,报错:selenium.common.exceptions.WebDriverException: Message: Unexpected ...

  6. selenium webdriver 启动三大浏览器Firefox,Chrome,IE

    selenium webdriver 启动三大浏览器Firefox,Chrome,IE 1.安装selenium 在联网的情况下,在Windows命令行(cmd)输入pip install selen ...

  7. Selenium Webdriver——操作隐藏的元素(三)switchTo().frame()

    在web 应用中经常会遇到frame 嵌套页面的应用,页WebDriver 每次只能在一个页面上识别元素,对于frame 嵌套内的页面上的元素,直接定位是定位是定位不到的.这个时候就需要通过switc ...

  8. Selenium Webdriver——操作隐藏的元素(二)display属性

    有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操作这个下拉框, ...

  9. Selenium Webdriver——操作隐藏的元素

    有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操作这个下拉框, ...

随机推荐

  1. Hystrix : 解决请求会被拒绝和抛出异常并且fallback不会被调用的问题

    启动脚本增加参数:-Dserver.tomcat.max-http-header-size=102400 增大Hystrix,ribbon的各项参数; hystrix: threadpool: def ...

  2. NOIP2017 Day1 T3 逛公园(最短路+拓扑排序+DP)

    神tm比赛时多清个零就有60了T T 首先跑出1起点和n起点的最短路,因为k只有50,所以可以DP.设f[i][j]表示比最短路多走i的长度,到j的方案数. 我们发现如果在最短路上的和零边会有后向性, ...

  3. bzoj4010: [HNOI2015]菜肴制作(拓扑排序+贪心+堆)

    这题不是求最小字典序...撕烤了半个小时才发现不对劲T T 这题是能让小的尽量前就尽量前,无论字典序...比如1能在2前面就一定要在2前面... 显然是要先拓扑排序,让小的尽量前转化成让大的尽量往后丢 ...

  4. 洛谷P1290 欧几里得的游戏

    题目描述 欧几里德的两个后代Stan和Ollie正在玩一种数字游戏,这个游戏是他们的祖先欧几里德发明的.给定两个正整数M和N,从Stan开始,从其中较大的一个数,减去较小的数的正整数倍,当然,得到的数 ...

  5. python学习(十三)进程和线程

    python多进程 from multiprocessing import Process import os def processFunc(name): print("child pro ...

  6. 使用git拉取github上的项目

    一. 安装Git 去Git官网,下载安装包,一路点next,默认安装. 安装之后,在空白处右键,菜单显示有 Git GUI Here 和 Git Bash Here ,表示Git安装成功. 二. 配置 ...

  7. 5 Techniques To Understand Machine Learning Algorithms Without the Background in Mathematics

    5 Techniques To Understand Machine Learning Algorithms Without the Background in Mathematics Where d ...

  8. Linux高级编程--01.vi命令

    VI是Linux/Unix下标配的一个纯字符界面的文本编辑器.由于不支持鼠标功能,也没有图形界面,相关的操作都要通过键盘指令来完成,需要记忆大量命令.因此很多人不大喜欢它,但同时由于键盘的方式往往比鼠 ...

  9. jquery键盘事件全记录

    很多时候,我们需要获取用户的键盘事件,下面就一起来看看jquery是如何操作键盘事件的. 一.首先需要知道的是: 1.keydown() keydown事件会在键盘按下时触发. 2.keyup() k ...

  10. 第一周 ch01 课下测试

    1.Amdahl定律说明,我们对系统的某个部分做出重大改进,可以显著获得一个系统的加速比.(B) A .正确 B .错误 解析:Amdahl定律,该定律的主要思想是,当我们对系统的某个部分加速时,其对 ...