当前位置:网站首页>selenium 浏览器(1)
selenium 浏览器(1)
2022-07-03 13:24:00 【不负韶华ღ】
概述
Selenium支持市场上所有主要浏览器,如Chrome、Firefox、Internet Explorer、Edge、Opera和Safari。WebDriver尽量使用浏览器内置的自动化支持来驱动浏览器。
selenium对浏览器的操作主要包括打开关闭浏览器,获取浏览器的信息(比如标题、网址等),定位网页中的元素,远程操控浏览器等,其中,最重要的部分就是定位网页中的元素。
功能
打开浏览器
1、打开Chrome浏览器。注意, Chrome浏览器和chromedriver的版本必须与主版本匹配。
options = ChromeOptions()
driver = webdriver.Chrome(options=options)
2、打开Edge浏览器。与Chrome类似, edgedriver的主要版本号必须与Edge浏览器的主要版本匹配。
options = EdgeOptions()
driver = webdriver.Edge(options=options)
3、打开Firefox浏览器。
options = FirefoxOptions()
driver = webdriver.Firefox(options=options)
4、打开Internet Explorer浏览器。
options = IEOptions()
driver = webdriver.Ie(options=options)
可以使用IE驱动程序在IE兼容模式下使用微软Edge。
options = IEOptions()
options.attach_to_edge_chrome = True
options.edge_executable_path = "/path/to/edge/browser"
driver = webdriver.Ie(options=options)
5、打开Opera浏览器。由于opera驱动程序不支持w3c语法,但基于Chrome,因此建议使用chromedriver驱动opera浏览器。与所有Chromium实现一样,确保浏览器版本与驱动程序版本匹配。
options = ChromeOptions()
options.binary_location = "path/to/opera/browser"
driver = webdriver.Chrome(options=options)
6、打开Safari浏览器。与Chromium和Firefox驱动程序不同,safaridriver是随操作系统一起安装的。要在Safari上启用自动化,请从命令行运行以下命令:
safaridriver --enable
然后再通过下列代码打开浏览器。
driver = webdriver.Safari()
关闭浏览器
当你完成了浏览器会话,你应该调用 quit 退出。退出将会关闭所有与 WebDriver 会话相关的窗口和选项卡、结束浏览器进程、结束后台驱动进程、通知 Selenium Grid 浏览器不再使用,以便可以由另一个会话使用它(如果您正在使用 Selenium Grid)。
driver.quit()
边栏推荐
- Thrift threadmanager and three monitors
- Dlopen() implements dynamic loading of third-party libraries
- 3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
- Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)
- Go language web development series 30: gin: grouping by version for routing
- Qt学习18 登录对话框实例分析
- 太阳底下无新事,元宇宙能否更上层楼?
- How to use lxml to judge whether the website announcement is updated
- Summary of common error reporting problems and positioning methods of thrift
- Comprehensive case of MySQL data addition, deletion, modification and query
猜你喜欢

SQL Injection (POST/Select)

Dlopen() implements dynamic loading of third-party libraries

双向链表(我们只需要关注插入和删除函数)

The solution of Chinese font garbled code in keil5

Go: send the get request and parse the return JSON (go1.16.4)

CVPR 2022 | interpretation of 6 excellent papers selected by meituan technical team

Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market

TensorBoard可视化处理案例简析

解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)

Golang — 命令行工具cobra
随机推荐
Go language unit test 4: go language uses gomonkey to test functions or methods
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
The solution of Chinese font garbled code in keil5
如何使用lxml判断网站公告是否更新
SQL Injection (AJAX/JSON/jQuery)
Red hat satellite 6: better management of servers and clouds
Summary of common error reporting problems and positioning methods of thrift
Multi person collaborative data annotation based on Baidu brain easydata from scratch
3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
How to promote the progress of project collaboration | community essay solicitation
Go 1.16.4: manage third-party libraries with Mod
RichView TRVStyle ListStyle 列表样式(项目符号编号)
How to use lxml to judge whether the website announcement is updated
研发团队资源成本优化实践
The shadow of the object at the edge of the untiy world flickers, and the shadow of the object near the far point is normal
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
Error running 'application' in idea running: the solution of command line is too long
ThreadPoolExecutor realizes multi-threaded concurrency and obtains the return value (elegant and concise way)
Qt学习18 登录对话框实例分析
Go 1.16.4: purpose of go mod tidy