当前位置:网站首页>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()
边栏推荐
- C language standard IO function sorting
- Sequence table (implemented in C language)
- GoLand 2021.2 configure go (go1.17.6)
- MapReduce implements matrix multiplication - implementation code
- Open PHP error prompt under Ubuntu 14.04
- [how to earn a million passive income]
- Universal dividend source code, supports the dividend of any B on the BSC
- IBEM mathematical formula detection data set
- 【被动收入如何挣个一百万】
- logback日志的整理
猜你喜欢
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
When updating mysql, the condition is a query
Implementation of Muduo asynchronous logging
MySQL 数据增删改查综合案例
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)
MySQL 数据处理值增删改
太阳底下无新事,元宇宙能否更上层楼?
JVM family - overview, program counter day1-1
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
随机推荐
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
Qt学习24 布局管理器(三)
[技术发展-24]:现有物联网通信技术特点
Thrift threadmanager and three monitors
Golang — template
Red hat satellite 6: better management of servers and clouds
IBEM mathematical formula detection data set
[技術發展-24]:現有物聯網通信技術特點
There is nothing new under the sun. Can the meta universe go higher?
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Several common optimization methods matlab principle and depth analysis
Spark practice 1: build spark operation environment in single node local mode
Open PHP error prompt under Ubuntu 14.04
【被动收入如何挣个一百万】
Qt学习21 Qt 中的标准对话框(下)
Qt学习25 布局管理器(四)
Halcon combined with C # to detect surface defects -- Halcon routine autobahn
windos 创建cordova 提示 因为在此系统上禁止运行脚本
项目协作的进度如何推进| 社区征文