博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Selenium+ChromeDriver使用记录
阅读量:4298 次
发布时间:2019-05-27

本文共 2178 字,大约阅读时间需要 7 分钟。

文章目录

Selenium+ChromeDriver使用记录

一、前言

  • Selenium
  1. 免费的分布式的自动化测试工具

  2. 多平台支持:windows、linux、MAC

  3. 多浏览器支持:ie、ff、safari、opera、chrome

  4. 多语言支持:C、 java、ruby、python、C#

  • ChromeDriver

WebDriver是一个开源工具,可用于跨多种浏览器自动测试Web应用程序。它提供了导航到网页,用户输入,JavaScript执行等功能。ChromeDriver是一个独立的服务器,它实现 了 。ChromeDriver可用于Android上的Chrome和台式机(Mac,Linux,Windows和ChromeOS)上的Chrome。

  • 开发环境
  1. Google Chrome 浏览器
  2. JDK 1.8+
  • 参考:
  • Selenium:

  • ChromeDriver:

  • Google Chrome:

  • Chrome 命令行参数:

  • XPath:

  • Java 正则表达式:

  • Jsoup官网:

二、正文

  • 下载并安装 Google Chrome 浏览器

资源下载:

  • 下载 ChormeDriver (对应 Google Chrome 浏览器版本) ,解压

资源下载:

  • 添加依赖
org.seleniumhq.selenium
selenium-java
3.141.59
  • 通过 chrome 的命令行参数,运行 headless 模式的 chrome 浏览器

“–disable-gpu”:不使用 GPU 加速

“–headless”:启动 chrome 的 headless 模式,即不会弹出浏览器界面

import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.chrome.ChromeOptions;import java.io.IOException;public class Bing {
public static void main(String[] args) throws IOException {
// chromedriver 解压路径 String chromeDriverFilePath = "C:/chromedriver_win32/chromedriver.exe"; // 配置环境变量 System.getProperties().setProperty("webdriver.chrome.driver" , chromeDriverFilePath); // 设置浏览器选项 ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--disable-gpu", "--headless"); WebDriver webDriver = new ChromeDriver(chromeOptions); webDriver.get("https://www.bing.com"); String content = webDriver.getPageSource(); webDriver.close(); // 输出内容 System.out.println(content); }}

三、其它

完整依赖

org.seleniumhq.selenium
selenium-java
3.141.59
org.seleniumhq.selenium
selenium-remote-driver
3.141.59
org.seleniumhq.selenium
selenium-api
3.141.59
org.seleniumhq.selenium
selenium-chrome-driver
3.141.59
org.seleniumhq.selenium
selenium-support
3.141.59

转载地址:http://rwnws.baihongyu.com/

你可能感兴趣的文章
常浏览的博客和网站
查看>>
Xcode 工程文件打开不出来, cannot be opened because the project file cannot be parsed.
查看>>
点击button实现Storyboard中TabBar Controller的tab切换
查看>>
Xcode 的正确打开方式——Debugging
查看>>
打包app出现的一个问题
查看>>
iOS在Xcode6中怎么创建OC category文件
查看>>
Expanding User-Defined Runtime Attributes in Xcode with Objective-C
查看>>
iOS7 UITabBar自定义选中图片显示为默认蓝色的Bug
查看>>
提升UITableView性能-复杂页面的优化
查看>>
25 iOS App Performance Tips & Tricks
查看>>
那些好用的iOS开发工具
查看>>
iOS最佳实践
查看>>
使用CFStringTransform将汉字转换为拼音
查看>>
更轻量的 View Controllers
查看>>
Chisel-LLDB命令插件,让调试更Easy
查看>>
时间格式化hh:mm:ss和HH:mm:ss区别
查看>>
When to use Delegation, Notification, or Observation in iOS
查看>>
Objective-C Autorelease Pool 的实现原理
查看>>
编程语言大牛王垠:编程的智慧,带你少走弯路
查看>>
ios指令集以及基于指令集的app包压缩策略
查看>>