selenium webdriver操作各浏览器

描述

本文主要是针对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%。

selenium webdriver操作各浏览器

 package 票务系统前台;

 import java.util.concurrent.TimeUnit;

 import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities; public class 浏览器操作 {
static WebDriver driver; public static void main(String[] args) {
// IE_open(driver);
// firefox_Open1(driver);
chrome_Open(driver);
} public static WebDriver chrome_Open(WebDriver driver) {
System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver_X64\\chromedriver_X64.exe");
ChromeOptions Options = new ChromeOptions();
Options.addArguments("user-data-dir=C:\\Users\\linxinmeng\\AppData\\Local\\Google\\Chrome\\User Data");
driver = new ChromeDriver(Options);
driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS); driver.get("http://www.baidu.com");
return driver;
} public static WebDriver IE_open(WebDriver driver) {
System.setProperty("webdriver.ie.driver", "C:\\Program Files (x86)\\Internet Explorer\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.get("http://www.baidu.com");
return driver; } public static WebDriver firefox_Open1(WebDriver driver) { System.setProperty("webdriver.firefox.bin", "D:\\软件应用宝\\Mozilla Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver", "D:\\软件应用宝\\Mozilla Firefox\\geckodriver.exe");
FirefoxOptions ffo = new FirefoxOptions();
driver = new FirefoxDriver(ffo);
driver.get("https://www.baidu.com");
return driver;
} }
上一篇:20179223《Linux内核原理与分析》第五周学习笔记


下一篇:20179223《Linux内核原理与解析》第六周学习笔记