当前位置: 首页 > news >正文

【selenium:webdriver原理】

webdriver原理

    • webdriver原理
    • 调用过程

webdriver原理

webdriver是按照Server-Cilent 的经典模式设计的

http request
Client->自动化脚本
Remote Server->任意浏览器

调用过程

我们可以通过logging 开启debug模式来捕捉客户端–>服务端发送的请求
打开百度,输入selenium,并点击搜索功能

from selenium import webdriver
import logginglogging.basicConfig(level=logging.DEBUG)
driver = webdriver.Chrome()
#打开百度页面
driver.get("https://www.baidu.com")
# 在搜索框中输入selenium
driver.find_element_by_name("wd").send_keys("selenium")
# 点击查询
driver.find_element_by_id("su").click()
#关闭浏览器
driver.quit()

Debug日志如下:

webdriver 启动目标浏览器chrome 并绑定到指定端口:54127

DEBUG:selenium.webdriver.remote.remote_connection:POST http://localhost:54127/session {"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "chrome", "platformName": "any", "goog:chromeOptions": {"extensions": [], "args": []}}}, "desiredCapabilities": {"browserName": "chrome", "version": "", "platform": "ANY", "goog:chromeOptions": {"extensions": [], "args": []}}}

开启一个HTTP连接,访问https://www.baidu.com

DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): localhost:54127
DEBUG:urllib3.connectionpool:http://localhost:54127 "POST /session HTTP/1.1" 200 688
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request
DEBUG:selenium.webdriver.remote.remote_connection:POST http://localhost:54127/session/f0c667fc89d08ed4451706a49ae81706/url {"url": "https://www.baidu.com"}

通过name查找搜索框

DEBUG:urllib3.connectionpool:http://localhost:54127 "POST /session/f0c667fc89d08ed4451706a49ae81706/url HTTP/1.1" 200 14
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request
DEBUG:selenium.webdriver.remote.remote_connection:POST http://localhost:54127/session/f0c667fc89d08ed4451706a49ae81706/element {"using": "css selector", "value": "[name=\"wd\"]"}

在搜索框中输入文字selenium

DEBUG:urllib3.connectionpool:http://localhost:54127 "POST /session/f0c667fc89d08ed4451706a49ae81706/element HTTP/1.1" 200 88
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request
DEBUG:selenium.webdriver.remote.remote_connection:POST http://localhost:54127/session/f0c667fc89d08ed4451706a49ae81706/element/cb40aab4-84fb-47cf-b4bc-669dc15e0c12/value {"text": "selenium", "value": ["s", "e", "l", "e", "n", "i", "u", "m"], "id": "cb40aab4-84fb-47cf-b4bc-669dc15e0c12"}
DEBUG:urllib3.connectionpool:http://localhost:54127 "POST /session/f0c667fc89d08ed4451706a49ae81706/element/cb40aab4-84fb-47cf-b4bc-669dc15e0c12/value HTTP/1.1" 200 14
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request

查找搜索按钮,并点击

DEBUG:selenium.webdriver.remote.remote_connection:POST http://localhost:54127/session/f0c667fc89d08ed4451706a49ae81706/element {"using": "css selector", "value": "[id=\"su\"]"}
DEBUG:urllib3.connectionpool:http://localhost:54127 "POST /session/f0c667fc89d08ed4451706a49ae81706/element HTTP/1.1" 200 88
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request
DEBUG:selenium.webdriver.remote.remote_connection:POST http://localhost:54127/session/f0c667fc89d08ed4451706a49ae81706/element/afe9dc25-5369-4f80-8831-ee045cc16d26/click {"id": "afe9dc25-5369-4f80-8831-ee045cc16d26"}
DEBUG:urllib3.connectionpool:http://localhost:54127 "POST /session/f0c667fc89d08ed4451706a49ae81706/element/afe9dc25-5369-4f80-8831-ee045cc16d26/click HTTP/1.1" 200 14
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request

删除远程连接关闭浏览器

DEBUG:selenium.webdriver.remote.remote_connection:DELETE http://localhost:54127/session/f0c667fc89d08ed4451706a49ae81706 {}
DEBUG:urllib3.connectionpool:http://localhost:54127 "DELETE /session/f0c667fc89d08ed4451706a49ae81706 HTTP/1.1" 200 14
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 达梦数据库的系统视图v$cachesql
  • C#中计算矩阵(数学库下载和安装)
  • 终极指南:3D 数据科学系统和工具
  • Kotlin简记
  • 卓越运营必备神器:规划复杂项目、使用标准的项目模板,看Minitab Workspace!
  • Adaboost集成学习 | Matlab实现基于ELM-Adaboost极限学习机结合Adaboost集成学习故障诊断
  • javascript:判断输入值是数字还是字母
  • Spring Boot(八十四):集成Thumbnailator来生成缩略图
  • 机器人抓取与操作的挑战与进展——挑战赛角度
  • STM32CubeMX软件使用(超详细)
  • 【从零开始一步步学习VSOA开发】运行hellovsoa
  • 使用 Elastic Observability 中的 OpenTelemetry 进行基础设施监控
  • Android逆向之H5类型app逆向
  • 【深入探秘Hadoop生态系统】全面解析各组件及其实际应用
  • 本科阶段最后一次竞赛Vlog——2024年智能车大赛智慧医疗组准备全过程——4Bin模型转化过程
  • Asm.js的简单介绍
  • Git的一些常用操作
  • IOS评论框不贴底(ios12新bug)
  • JavaScript/HTML5图表开发工具JavaScript Charts v3.19.6发布【附下载】
  • java第三方包学习之lombok
  • Java应用性能调优
  • JS学习笔记——闭包
  • npx命令介绍
  • python 学习笔记 - Queue Pipes,进程间通讯
  • vue自定义指令实现v-tap插件
  • 阿里云前端周刊 - 第 26 期
  • 成为一名优秀的Developer的书单
  • 程序员最讨厌的9句话,你可有补充?
  • 分类模型——Logistics Regression
  • 记一次删除Git记录中的大文件的过程
  • 坑!为什么View.startAnimation不起作用?
  • 什么软件可以提取视频中的音频制作成手机铃声
  • 适配iPhoneX、iPhoneXs、iPhoneXs Max、iPhoneXr 屏幕尺寸及安全区域
  • 首页查询功能的一次实现过程
  • 小程序开发之路(一)
  • 自定义函数
  • ​1:1公有云能力整体输出,腾讯云“七剑”下云端
  • ​数据链路层——流量控制可靠传输机制 ​
  • ​中南建设2022年半年报“韧”字当头,经营性现金流持续为正​
  • #知识分享#笔记#学习方法
  • (9)STL算法之逆转旋转
  • (C语言)fgets与fputs函数详解
  • (void) (_x == _y)的作用
  • (非本人原创)史记·柴静列传(r4笔记第65天)
  • (附源码)ssm高校运动会管理系统 毕业设计 020419
  • (六)DockerCompose安装与配置
  • (三)SvelteKit教程:layout 文件
  • (三维重建学习)已有位姿放入colmap和3D Gaussian Splatting训练
  • (已解决)什么是vue导航守卫
  • (转)Linq学习笔记
  • (转)linux 命令大全
  • .form文件_一篇文章学会文件上传
  • .Net Attribute详解(上)-Attribute本质以及一个简单示例
  • .NET C# 使用GDAL读取FileGDB要素类
  • .net framework 4.8 开发windows系统服务