我们爬取网页过程中,经常发现我们想要获得的数据并不能简单的通过解析HTML代码获取
1. 使用示例
2. 详细介绍
2.1 声明浏览器对象
2.2 访问页面
2.3 查找元素
2.3.1 单个元素
下面是详细的元素查找方法
第二种:
2.3.2 多个元素
2.4 元素交互操作
比如说在搜索框内输入文字:
2.5 交互动作
2.6 执行JavaScript
比如拖拽下拉
2.7 获取元素信息
2.7.1 获取属性
2.8 Frame
2.9 等待
2.9.1 隐式等待
需要特别说明的是:
2.9.2 显式等待
2.10 浏览器的前进/后退
2.11 对Cookies进行操作
2.12 选项卡管理
就可以使用selenium来实现。
在H5开发中,经常会开发搜索功能,商品列表、订单列表、客户列表等等,都需要搜索,所以程序猿(程序媛)们都会遇到这样的需求,点击搜索input时,弹出的键盘,有“搜索”按钮,点击搜索调用接口搜索。今天就来讲讲怎么搞定这个需求。
H5中input输入框如何实现原生键盘搜索功能
<form action="javascript:;" id="searchFrom" onsubmit="searchList"> <input type="search" value="" placeholder="搜索Javan的博客" /> </form>
元素绑定方法调用
function searchList(){ // do something }
jquery监听
$('#searchFrom').bind('submit', function () { // do something });
H5中input输入框如何实现原生键盘搜索功能
input[type=search]::-webkit-search-cancel-button{ -webkit-appearance: none; // 此处只是去掉默认的小× }
自定义样式
input[type=search]::-webkit-search-cancel-button{ -webkit-appearance: none; position: relative; height: 20px; width: 20px; border-radius: 50%; background-color: #EBEBEB; } input[type=search]::-webkit-search-cancel-button:after{ position: absolute; content: 'x'; left: 25%; top: -12%; font-size: 20px; color: #fff; }
喜欢小编的点击关注,了解更多资源!
一、 简介
二、 webDirver 的 dirver
三、 webDirver 使用前准备
//前提是先安装好NodeJS mkdir test && cd test npm init //这里根据提示一步步初始化一个新的NodeJS项目 npm install selenium-webdriver --save //安装WebDriver JavaScript SDK的npm依赖
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.0</version> </dependency>
四、 webDirver 使用
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; /** * webDirver 打开各种浏览器 * @author outman * @date 2018-11-07 * */ public class Demo_02 { public static void main(String[] args) { // openFirFox(); // openIE(); openChrome(); } /** * 打开谷歌浏览器 * */ private static void openChrome() { // chromedriver.exe 下载地址 : http://chromedriver.storage.googleapis.com/index.html // 注意: 下载驱动时驱动版本要与selenium 版本一致 System.setProperty("webdriver.chrome.driver","D:\\DevelopSoftware\\chromedriver_win32\\chromedriver.exe"); WebDriver dirver = new ChromeDriver(); // 在执行操作是可能会报错: Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created: Chrome version must be >= 68.0.3440.0 // 解決: 使chromedriver 版本与chrome 版本相对应 参考chromedriver与chrome 版本映射关系 https://blog.csdn.net/huilan_same/article/details/51896672 dirver.get("http://www.baidu.com"); } /** * 打开IE浏览器 * */ private static void openIE() { // IEDriverServer.exe 下载地址 https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver // 注意: 下载驱动时驱动版本要与selenium 版本一致 // 可能报错:Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. // 解决: 设置internet选项 -- 安全 -- 把所有的启动保护模式都关闭 System.setProperty("webdriver.ie.driver", "D:\\DevelopSoftware\\IEDriverServer_x64_3.141.0\\IEDriverServer.exe"); WebDriver dirver = new InternetExplorerDriver(); dirver.get("http://www.baidu.com"); } /** * 打开火狐浏览器 * @throws InterruptedException * */ private static void openFirFox() throws InterruptedException { // geckodriver 下载地址: https://github.com/mozilla/geckodriver System.setProperty("webdriver.gecko.driver", "D:\\DevelopSoftware\\geckodriver-v0.23.0-win64\\geckodriver.exe"); //读取获取浏览器二进制文件 System.setProperty("webdriver.firefox.bin", "D:\\应用\\FoxMail\\firefox.exe"); WebDriver dirver = new FirefoxDriver(); dirver.get("http://www.baidu.com"); } }
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; /** * 定位dom元素 * * @author outman * @date 2018-11-07 */ public class Demo_03 { public static void main(String[] args) { // 获取驱动并打开浏览器 WebDriver dirver = openFirFox(); // 定位dom 元素 findElement(dirver); } /** * 定位dom 元素 */ private static void findElement(WebDriver dirver) { // 打开百度搜索页 dirver.get("http://www.baidu.com"); // 根据ID 定位元素 搜索框 WebElement kw = dirver.findElement(By.id("kw")); System.out.println("搜索框使用标签:" + kw.getTagName()); // 根据class 类名定位 搜索框 WebElement kw2 = dirver.findElement(By.className("s_ipt")); System.out.println("搜索框使用标签:" + kw2.getTagName()); // 根据tagName定位 搜索框 WebElement kw3 = dirver.findElement(By.tagName("input")); System.out.println("搜索框使用标签:" + kw3.getTagName()); // 根据name定位 搜索框 WebElement kw4 = dirver.findElement(By.name("wd")); System.out.println("搜索框使用标签:" + kw4.getTagName()); // 根据链接文字定位 页脚链接 WebElement kw5 = dirver.findElement(By.linkText("把百度设为主页")); System.out.println("链接使用标签:" + kw5.getTagName()); // 根据链接部分文字定位 页脚链接 WebElement kw6 = dirver.findElement(By.partialLinkText("百度")); System.out.println("链接使用标签:" + kw6.getTagName()); // 根据css选择器定位 搜索框 css选择器参考: http://www.w3school.com.cn/cssref/css_selectors.asp WebElement kw7 = dirver.findElement(By.cssSelector("#kw")); System.out.println("搜索框使用标签:" + kw7.getTagName()); // 根据xpath定位 搜索框 xpath语法参考: http://www.w3school.com.cn/xpath/xpath_syntax.asp WebElement kw8 = dirver.findElement(By.xpath("//input")); System.out.println("搜索框使用标签:" + kw8.getTagName()); } /** * 打开火狐浏览器 */ private static WebDriver openFirFox() { // geckodriver 下载地址: https://github.com/mozilla/geckodriver System.setProperty("webdriver.gecko.driver", "D:\\DevelopSoftware\\geckodriver-v0.23.0-win64\\geckodriver.exe"); // 读取获取浏览器二进制文件 System.setProperty("webdriver.firefox.bin", "D:\\应用\\FoxMail\\firefox.exe"); WebDriver dirver = new FirefoxDriver(); return dirver; } }
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; /** * 操作dom * * @author outman * @date 2018-11-07 */ public class Demo_04 { public static void main(String[] args) { // 打开浏览器 WebDriver dirver = openFirFox(); // 执行操作 doExcult(dirver); } /** * 执行操作 */ private static void doExcult(WebDriver dirver) { // 打开百度 dirver.get("http://www.baidu.com"); // 获取元素 百度一下按钮 WebElement sbtn = dirver.findElement(By.cssSelector("#su")); // 获取属性的值 System.out.println("按钮文字:"+sbtn.getAttribute("value")); // 获取元素 页脚链接 WebElement linkOne = dirver.findElement(By.cssSelector("#setf")); // 获取文本内容 System.out.println("链接文本:"+linkOne.getText()); //连续获取元素 WebElement soutuBtn = dirver.findElement(By.className("fm")); WebElement sInput = soutuBtn.findElement(By.tagName("span")).findElement(By.name("wd")); System.out.println("搜索框使用标签:"+sInput.getTagName()); //向input输入文字 sInput.sendKeys("百度一下"); System.out.println("搜索框内容:"+sInput.getAttribute("value")); //清空input 元素内容 sInput.clear(); System.out.println("搜索框内容:"+sInput.getAttribute("value")); //点击按钮 sInput.sendKeys("百度一下"); sbtn.click(); //提交表单 sInput.clear(); sInput.sendKeys("百度两下"); sbtn.submit(); } /** * 打开火狐浏览器 */ private static WebDriver openFirFox() { // geckodriver 下载地址: https://github.com/mozilla/geckodriver System.setProperty("webdriver.gecko.driver", "D:\\DevelopSoftware\\geckodriver-v0.23.0-win64\\geckodriver.exe"); // 读取获取浏览器二进制文件 System.setProperty("webdriver.firefox.bin", "D:\\应用\\FoxMail\\firefox.exe"); WebDriver dirver = new FirefoxDriver(); return dirver; } }
import org.openqa.selenium.Dimension; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Point; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; /** * 操作窗口 * * @author outman * @date 2018-11-07 */ public class Demo_05 { public static void main(String[] args) { // 打开浏览器 WebDriver dirver = openFirFox(); // 执行操作 doExcult(dirver); } /** * 执行操作 */ private static void doExcult(WebDriver dirver) { // 创建js 执行对象 JavascriptExecutor jsExceut = (JavascriptExecutor) dirver; // 导航到百度 dirver.get("http://www.baidu.com"); // 创建多个窗口 String js = "window.open(\"https://www.sogou.com\");"; String js2 = "window.open(\"http://www.w3school.com.cn/xpath/xpath_syntax.asp\");"; // 当只传入js脚本时 , 默认执行该js 的对象时浏览器 jsExceut.executeScript(js); jsExceut.executeScript(js2); // 设置窗口位置 dirver.manage().window().setPosition(new Point(100, 100)); // 设置窗口大小 dirver.manage().window().setSize(new Dimension(500 , 200)); // 最大化窗口 dirver.manage().window().maximize(); // 全屏 dirver.manage().window().fullscreen(); } /** * 打开火狐浏览器 */ private static WebDriver openFirFox() { // geckodriver 下载地址: https://github.com/mozilla/geckodriver System.setProperty("webdriver.gecko.driver", "D:\\DevelopSoftware\\geckodriver-v0.23.0-win64\\geckodriver.exe"); // 读取获取浏览器二进制文件 System.setProperty("webdriver.firefox.bin", "D:\\应用\\FoxMail\\firefox.exe"); WebDriver dirver = new FirefoxDriver(); return dirver; } }
import java.util.Set; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; /** * 在窗口或Frame 之间切换 * * @author outman * @date 2018-11-07 */ public class Demo_06 { public static void main(String[] args) { // 打开浏览器 WebDriver dirver = openFirFox(); // 执行操作 doExecute(dirver); } /** * 执行操作 * */ private static void doExecute(WebDriver dirver) { JavascriptExecutor jsExecute = (JavascriptExecutor) dirver; String openWindowPre = "window.open('"; String openWindowSuf = "');"; String url_1 = "https://www.sogou.com"; String url_2 = "http://田杰.wang"; // 打开多个窗口 dirver.get("http://www.baidu.com"); // jsExecute.executeScript(openWindowPre+url_1+openWindowSuf); // jsExecute.executeScript(openWindowPre+url_2+openWindowSuf); // 获取当前窗口的handle String windowHandle = dirver.getWindowHandle(); System.out.println("当前浏览器handle:"+windowHandle); // 列出浏览器所有窗口的handle Set<String> windowHandles = dirver.getWindowHandles(); System.out.println("所有窗口的handle:"+windowHandles); // 获取当前页面标题 String title = dirver.getTitle(); System.out.println("当前页面标题:"+title); // 获取当前页面源码 String pageSource = dirver.getPageSource(); //System.out.println("当前页面源码:"+pageSource); // 获取当前页面url String currentUrl = dirver.getCurrentUrl(); System.out.println("当前页面url:"+currentUrl); // 聚焦到顶部窗口 或 顶部frame WebDriver defaultContent = dirver.switchTo().defaultContent(); // 返回到当前聚焦的元素 如果没有聚焦的元素 则返回body WebElement activeElement = dirver.switchTo().activeElement(); // 切换单当前活跃的提示窗 // Alert alert = dirver.switchTo().alert(); //没有找到alert会抛异常 // 切换到指定窗口 WebDriver window = dirver.switchTo().window(windowHandle);// 传入 name 或者handle // 切换frame WebDriver frame = dirver.switchTo().frame(""); // 切换到父frame WebDriver parentFrame = dirver.switchTo().parentFrame(); } /** * 打开火狐浏览器 */ private static WebDriver openFirFox() { // geckodriver 下载地址: https://github.com/mozilla/geckodriver System.setProperty("webdriver.gecko.driver", "D:\\DevelopSoftware\\geckodriver-v0.23.0-win64\\geckodriver.exe"); // 读取获取浏览器二进制文件 System.setProperty("webdriver.firefox.bin", "D:\\应用\\FoxMail\\firefox.exe"); WebDriver dirver = new FirefoxDriver(); return dirver; } }
点击Alert窗口中的OK: driver.switchTo().alert().accept(); 点击Alert窗口中的Cancel: driver.switchTo().alert().dismiss(); 向Alert窗口输入文字: driver.switchTo().alert().sendKeys(‘abcd’);
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; /** * 操作浏览器的导航及地址栏 * * @author outman * @date 2018-11-07 */ public class Demo_07 { public static void main(String[] args) { // 打开浏览器 WebDriver dirver = openFirFox(); // 执行操作 doExecute(dirver); } /** * 执行操作 * */ private static void doExecute(WebDriver dirver) { //导航到百度 dirver.get("http://www.baidu.com"); //导航到搜狗 dirver.navigate().to("https://www.sogou.com"); //导航后退 dirver.navigate().back(); //导航前进 dirver.navigate().forward(); //导航刷新 dirver.navigate().refresh(); } /** * 打开火狐浏览器 */ private static WebDriver openFirFox() { // geckodriver 下载地址: https://github.com/mozilla/geckodriver System.setProperty("webdriver.gecko.driver", "D:\\DevelopSoftware\\geckodriver-v0.23.0-win64\\geckodriver.exe"); // 读取获取浏览器二进制文件 System.setProperty("webdriver.firefox.bin", "D:\\应用\\FoxMail\\firefox.exe"); WebDriver dirver = new FirefoxDriver(); return dirver; } }
import java.util.Set; import org.openqa.selenium.Cookie; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; /** * 操作cookie */ public class Demo_08 { public static void main(String[] args) { // 打开浏览器 WebDriver dirver = openFirFox(); // 执行操作 doExecute(dirver); } /** * 执行操作 */ private static void doExecute(WebDriver dirver) { dirver.get("http://www.baidu.com"); // 添加cookie Cookie addCookie = new Cookie("outman", "1317361873dfdfv"); dirver.manage().addCookie(addCookie); // 得到所有的cookie Set<Cookie> cookies = dirver.manage().getCookies(); for(Cookie cookie : cookies) { System.out.println("cookie:"+cookie); } System.out.println("所有cookie:"+cookies); // 根据名字获取cookie Cookie outman = dirver.manage().getCookieNamed("outman"); System.out.println("outman的cookie:"+outman); // 根据name删除cookie dirver.manage().deleteCookieNamed("outman"); Cookie outman2 = dirver.manage().getCookieNamed("outman"); System.out.println("outman的cookie:"+outman2); // 删除指定的cookie dirver.manage().deleteCookie(new Cookie("outman" , "")); Cookie outman3 = dirver.manage().getCookieNamed("outman"); System.out.println("outman的cookie:"+outman3); // 删除所有cookie dirver.manage().deleteAllCookies(); Set<Cookie> cookies2 = dirver.manage().getCookies(); System.out.println("所有cookie:"+cookies2); } /** * 打开火狐浏览器 */ private static WebDriver openFirFox() { // geckodriver 下载地址: https://github.com/mozilla/geckodriver System.setProperty("webdriver.gecko.driver", "D:\\DevelopSoftware\\geckodriver-v0.23.0-win64\\geckodriver.exe"); // 读取获取浏览器二进制文件 System.setProperty("webdriver.firefox.bin", "D:\\应用\\FoxMail\\firefox.exe"); WebDriver dirver = new FirefoxDriver(); return dirver; } }
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; /** * 高级用户接口 * * @author outman * @dete 2018-11-07 */ public class Demo_09 { public static void main(String[] args) { // 打开浏览器 WebDriver dirver = openFirFox(); // 执行操作 doExecute(dirver); } /** * 执行操作 */ private static void doExecute(WebDriver dirver) { dirver.get("http://www.baidu.com"); Actions action = new Actions(dirver); WebElement trnews = dirver.findElement(By.name("tj_trnews")); WebElement trxueshu = dirver.findElement(By.name("tj_trxueshu")); WebElement kw = dirver.findElement(By.id("kw")); // perform() 方法为整个动作完成之后的提交操作 // 移动鼠标至某个dom元素 (选中页面 新闻) // action.moveToElement(trnews).perform(); // 鼠标点击元素 // action.click(trnews).perform(); // 鼠标点击并悬停 // action.clickAndHold(trnews).perform(); // 在指定元素上点击右键 // action.contextClick(trnews).perform(); // 在指定元素上双击 // action.doubleClick(trnews).perform(); // 点击并拖拽 (将资源拖到 指定元素 , 或指定位置) // action.dragAndDrop(trnews , trxueshu).perform(); // action.dragAndDropBy(trnews, 100, 100).perform();; // 键盘按下 // action.keyDown(Keys.ENTER).perform(); // 键盘按键抬起 // action.keyUp(Keys.ENTER).perform(); // 将光标移动至指定位置 // action.moveByOffset(100, 100).perform(); // 暂停指定的时间 for(int i = 0 ; i<10 ;i++) { kw.sendKeys(i+""); action.pause(1000).perform(); } // 释放鼠标 action.release().perform(); } /** * 打开火狐浏览器 */ private static WebDriver openFirFox() { // geckodriver 下载地址: https://github.com/mozilla/geckodriver System.setProperty("webdriver.gecko.driver", "D:\\DevelopSoftware\\geckodriver-v0.23.0-win64\\geckodriver.exe"); // 读取获取浏览器二进制文件 System.setProperty("webdriver.firefox.bin", "D:\\应用\\FoxMail\\firefox.exe"); WebDriver dirver = new FirefoxDriver(); return dirver; } }
import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; /** * 操作等待 * @author outman * @date 2018-11-07 * */ public class Demo_10 { public static void main(String[] args) { // 打开浏览器 WebDriver dirver = openFirFox(); // 执行操作 doExecute(dirver); } /** * 执行操作 * */ private static void doExecute(WebDriver driver) { // 显式等待 driver.get("http://www.baidu.com"); WebElement kw = driver.findElement(By.id("kw")); kw.sendKeys("webDriver"); // 显式等待 针对单个元素 隐式等待针对整个页面 // 最大超时时间是10秒 // 默认每隔500毫秒扫描一次 如果检测到结果则返回 WebDriverWait wait = new WebDriverWait(driver, 10, 1); //获取第一条结果 WebElement resultOne = wait.until(new ExpectedCondition<WebElement>() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("1")); } }).findElement(By.tagName("h3")).findElement(By.tagName("a")); System.out.println(resultOne.getText()); resultOne.click(); //隐式等待 //设置页面加载时间最大为10秒 // driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); // driver.get("http://www.baidu.com"); // // //定位对象设置10秒超时时间 , 10秒还定位不到则抛出异常 // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // WebElement kw = driver.findElement(By.id("kw")); // // //异步脚本执行超时时间设置为3秒 // driver.manage().timeouts().setScriptTimeout(1, TimeUnit.SECONDS); } /** * 打开火狐浏览器 */ private static WebDriver openFirFox() { // geckodriver 下载地址: https://github.com/mozilla/geckodriver System.setProperty("webdriver.gecko.driver", "D:\\DevelopSoftware\\geckodriver-v0.23.0-win64\\geckodriver.exe"); // 读取获取浏览器二进制文件 System.setProperty("webdriver.firefox.bin", "D:\\应用\\FoxMail\\firefox.exe"); WebDriver dirver = new FirefoxDriver(); return dirver; } }
// 创建js 执行对象 JavascriptExecutor jsExceut = (JavascriptExecutor) dirver; // 导航到百度 dirver.get("http://www.baidu.com"); // 创建多个窗口 String js = "window.open(\"https://www.sogou.com\");"; String js2 = "window.open(\"http://www.w3school.com.cn/xpath/xpath_syntax.asp\");"; // 当只传入js脚本时 , 默认执行该js 的对象时浏览器 jsExceut.executeScript(js); jsExceut.executeScript(js2);
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; /** * 同时启动多个浏览器执行测试 */ public class Demo_11 { public static void main(String[] args) { for (int i = 0; i < 5; i++) { new Thread(new Runnable() { public void run() { new Demo_11FirFox().doExecute(); } }).start(); new Thread(new Runnable() { public void run() { new Demo_11IE().doExecute(); } }).start(); new Thread(new Runnable() { public void run() { new Demo_11Chrome().doExecute(); } }).start(); } } public void doExecute(WebDriver driver) { driver.get("http://www.baidu.com"); WebElement sbtn = driver.findElement(By.id("kw")); sbtn.sendKeys("webDriver"); WebDriverWait wait = new WebDriverWait(driver, 10, 1); WebElement resultOne = wait.until(new ExpectedCondition<WebElement>() { public WebElement apply(WebDriver input) { return input.findElement(By.id("1")); } }).findElement(By.tagName("h3")).findElement(By.tagName("a")); // 点击第一条 resultOne.click(); } }
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Demo_11Chrome extends Demo_11 { public WebDriver driver = null; public Demo_11Chrome() { System.setProperty("webdriver.chrome.driver","D:\\DevelopSoftware\\chromedriver_win32\\chromedriver.exe"); driver = new ChromeDriver(); } public void doExecute() { super.doExecute(driver); } }
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Demo_11FirFox extends Demo_11 { private WebDriver driver = null; public Demo_11FirFox() { System.setProperty("webdriver.gecko.driver", "D:\\DevelopSoftware\\geckodriver-v0.23.0-win64\\geckodriver.exe"); //读取获取浏览器二进制文件 System.setProperty("webdriver.firefox.bin", "D:\\应用\\FoxMail\\firefox.exe"); driver = new FirefoxDriver(); } public void doExecute() { super.doExecute(driver); } }
import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; public class Demo_11IE extends Demo_11 { private WebDriver driver = null; public Demo_11IE() { System.setProperty("webdriver.ie.driver", "D:\\DevelopSoftware\\IEDriverServer_x64_3.141.0\\IEDriverServer.exe"); driver = new InternetExplorerDriver(); } public void doExecute() { super.doExecute(driver); } }
后记
感谢各位客官的阅读 , 如果文章中有错误或剖析的不够透彻还请您能够给不吝赐教在评论中告诉小编 , 以便小编能够及时调整文章内容 , 为大家带来更加优质的文章
*请认真填写需求信息,我们会在24小时内与您取得联系。