Skip to Content
使用 Java 实践 Selenium WebDriver
book

使用 Java 实践 Selenium WebDriver

by Boni Garcia
May 2025
Intermediate to advanced
422 pages
6h 1m
Chinese
O'Reilly Media, Inc.
Content preview from 使用 Java 实践 Selenium WebDriver

附录 A. Selenium 4 的新功能

本附录概述了 Selenium 4 的新功能。该内容有两个目的。首先,它列举了Selenium套件核心组件(即WebDriver、Driver和IDE)中的新功能,并提供了本书中解释每个方面的章节链接。此外,本附录还介绍了Selenium项目中随Selenium 4而改变的其他方面,如文档和管理。第二个目的是在从 Selenium 3 迁移到 Selenium 4 时,确定废弃的部分和相应的新功能。

Selenium WebDriver

Selenium WebDriver 4.0.0 的第一个稳定版本于 2021 年 10 月 13 日发布。表 A-1总结了该版本与前稳定版本(即 Selenium WebDriver 3.141.59)相比最相关的新功能。

表 A-1. Selenium WebDriver 4 中的新功能
特点 说明 章节 部门

全面采用 W3C WebDriver

Selenium WebDriver API 与驱动程序之间的标准通信协议

第 1 章

"Selenium WebDriver

相对定位器

定位策略基于其他网络元素的邻近程度

第三章

"相对定位器"

固定脚本

在 WebDriver 会话中附加一段JavaScript

第 4 章

"固定脚本"

元素截图

截图网页元素(而不是整个页面)

第 4 章

"WebElement 截图

阴影 DOM

无缝访问到影子树

第 4 章

"影子 DOM"

打开新窗口和标签页

改进了浏览不同窗口和选项卡的方法

第 4 章

"选项卡和 Windows"

装饰

WebDriver 对象的封装器,用于实现事件监听器

第 4 章

"事件监听器"

Chrome 浏览器开发工具协议

在基于 Chromium 的浏览器(如 Chrome 浏览器和 Edge 浏览器)中本地访问到 DevTools

第 5 章

"Chrome DevTools 协议

网络拦截

将后端请求存根化,拦截网络流量

第 5 章

"网络拦截器"

基本认证

用于基本和摘要验证的简化 API

第 5 章

"基本和摘要验证"

整页截图

获取网页的全部内容

第 5 章

"整页截图"

地点背景

模拟地理位置坐标

第五章

"地点背景"

打印为 PDF

将网页保存为 PDF 文档

第 5 章

"打印页面"

WebDriver BiDi

驱动程序和浏览器之间的双向通信

第 5 章

"WebDriver BiDi"

迁移指南

本节总结了将使用 Selenium WebDriver 3 的现有代码库迁移到版本 4 所需的更改。

定位器

Selenium WebDriver 4 中删除了查找元素(FindsBy 接口)的实用方法。表 A-2比较了 Selenium WebDriver 中用于查找 Web 元素的新旧 API。有关此功能的更多详情,请参阅"定位 WebElements"。

表 A-2. Selenium WebDriver 4 中网络元素位置的迁移
Selenium WebDriver 3 Selenium WebDriver 4
driver.findElementByTagName("tagName");
driver.findElementByLinkText("link");
driver
    .findElementByPartialLinkText("partLink");
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

现代 Java 配方

现代 Java 配方

Ken Kousen
Java Server Pages

Java Server Pages

Hans Bergsten

Publisher Resources

ISBN: 9798341657847