当前位置:网站首页>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()
边栏推荐
- Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
- Windos creates Cordova prompt because running scripts is prohibited on this system
- The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
- Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
- Flutter动态化 | Fair 2.5.0 新版本特性
- ThreadPoolExecutor realizes multi-threaded concurrency and obtains the return value (elegant and concise way)
- [quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
- mysql中的字段问题
- Qt学习18 登录对话框实例分析
- How to promote the progress of project collaboration | community essay solicitation
猜你喜欢

Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)

HALCON联合C#检测表面缺陷——HALCON例程autobahn

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

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

使用vscode查看Hex或UTF-8编码

使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例

The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can

Complete deep neural network CNN training with tensorflow to complete picture recognition case 2

Installation impression notes

Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
随机推荐
SQL Injection (GET/Select)
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
Father and basketball
使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Dynamic programming 01 knapsack and complete knapsack
windos 创建cordova 提示 因为在此系统上禁止运行脚本
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
JS general form submission 1-onsubmit
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
太阳底下无新事,元宇宙能否更上层楼?
软件测试工作那么难找,只有外包offer,我该去么?
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
MySQL 数据处理值增删改
全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场
MySQL 数据增删改查综合案例
Mastering the cypress command line options is the basis for truly mastering cypress
使用vscode查看Hex或UTF-8编码
8 Queen question
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.