python3 selenium 切换窗口的几种方法

【Python】Selenium怎么切换浏览器的页面 我们在爬网使用Selenium进行测试的时候,有时候想要点击浏览器里面的网址,跳到另一个页面上,获取第二个页面的内容。这里主要使用window_handles来切换浏览器的页面 阅读详情

第一种方法:

使用场景:

打开多个窗口,需要定位到新打开的窗口

使用方法:

# 获取打开的多个窗口句柄
windows = driver.window_handles
# 切换到当前最新打开的窗口
driver.switch_to.window(windows[-1])

举例说明:

 1 # _._ coding:utf-8 _._
 2 
 3 """
 4 :author: 花花测试
 5 :time: 2017.05.03
 6 :content: 使用第一种方法切换浏览器
 7 """
 8 
 9 from selenium import webdriver
10 import time
11 
12 #   打开课工场网站主页【第一个窗口】
13 driver = webdriver.Chrome()
14 driver.get('http://www.kgc.cn/')
15 driver.maximize_window()
16 
17 #   点击全部课程,进入课程库【第二个窗口】
18 driver.find_element_by_link_text('全部课程').click()
19 time.sleep(3)
20 
21 #   使用第一种方法切换浏览器【切换到第二个窗口】
22 windows = driver.window_handles
23 driver.switch_to.window(windows[-1])
24 time.sleep(3)
25 
26 #   点击课程库中的某个课程,进入课程详情界面【在第二个窗口页面进行元素点击操作,来判断窗口是否切换成功】
27 driver.find_element_by_xpath('//*[@id="yw1"]/ul/li[2]').click()
28 time.sleep(3)
29 
30 #   关闭浏览器
31 driver.quit()
32 print('测试通过')

 

第二种方法:

使用场景:

打开两个窗口,需要定位到新打开的窗口

使用方法:

# 获得打开的第一个窗口句柄
window_1 = driver.current_window_handle
# 获得打开的所有的窗口句柄
windows = driver.window_handles
# 切换到最新的窗口
for current_window in windows:
    if current_window != window_1:
        driver.switch_to.window(current_window)

举例说明:

 
 1 # _._ coding:utf-8 _._
 2 
 3 """
 4 :author: 花花测试
 5 :time: 2017.05.03
 6 :content: 使用第二种方法切换浏览器
 7 """
 8 
 9 from selenium import webdriver
10 import time
11 
12 from selenium import webdriver
13 import time
14 
15 #   打开课工场网站主页【第一个窗口】
16 driver = webdriver.Chrome()
17 driver.get('http://www.kgc.cn/')
18 driver.maximize_window()
19 
20 #   点击全部课程,进入课程库【第二个窗口】
21 driver.find_element_by_link_text('全部课程').click()
22 time.sleep(3)
23 
24 #   使用第二种方法切换浏览器【切换到第二个窗口】
25 window_1 = driver.current_window_handle
26 windows = driver.window_handles
27 for current_window in windows:
28     if current_window != window_1:
29         driver.switch_to.window(current_window)
30 time.sleep(3)
31 
32 #   点击课程库中的某个课程,进入课程详情界面【在第二个窗口页面进行元素点击操作,来判断窗口是否切换成功】
33 driver.find_element_by_xpath('//*[@id="yw1"]/ul/li[2]').click()
34 time.sleep(3)
35 
36 #   关闭浏览器
37 driver.quit()
38 print('测试通过')
 
两种方法的区别:
1、第一种方法比较简单,能提升整体代码的性能
2、第二种方法是大家最常用的方法,比较容易理解


说明:

1、我的脚本都是以课工场为例,如果有什么不明白的地方,欢迎大家留言,我看的话会及时给大家解答

2、辛苦原创,转载请注明出处

Python+Selenium-13-switch_to.window切换窗口 切换窗口 使用场景 (1)点击右侧某一个来访用户,会重新打开一个新tab (2)新开的页面,是来访用户的主页,包含用户名 (3)我们现在做这样一件事,就是判断我们点击的“来访用户”与链接跳转的用户主页是否对应 比如:我们点击的是“羿飞教育管理员”这个来访用户,点击后,会进入管理员的主页 思路 (1)先定位到最近来访中的某个用户(列表第一个为例),保存下用户名,点击... 阅读详情

相关推荐

第08课:子窗口交互

用 open 方法打开的子窗口也会面临和其他窗口交互的问题,交互无外乎互相传递数据,并接收其他窗口传递过来的数据。 8.1 最简单的传递接收数据 向 open 方法创建的子窗口传递数据有多种方法,其中之一就是使用 BrowserWindowProxy.postMessage 方法,该方法可以向指定的窗口传递任意类型的数据和来源(origin),如果不知来源,可以使用星号 '*' 代替,关于来源是什...

一个被知识诅咒的人 1306

selenium+python切换浏览器窗口

selenium在当前浏览器页面打开了新的窗口,此时如果要聚焦到新开的浏览器窗口,就需要切换到新的窗口,切换窗口的操作selenium+python示例如下:

梦里有阳光 2241

【python】【selenium】python如何用selenium切换窗口

selenium的操作都需要人为地去控制,包括如果你打开了一个新窗口,就有必要将driver重新定位到新窗口,不然元素定位都会出错。所以,切换窗口是selenium自动化程序的必备功能,建议写成公共函数方便调用。 上述是比较简单的一种写法,当有两个窗口时,新窗口就是windows[1] 在这个基础上,可以写成更通用的 当然,只这么写是有缺陷的,最好加上len(windows)>=1的前提条件。...

每日出拳老爷子的博客 1575

『python爬虫』23. selenium之窗口切换与iframe(保姆级图文)

『python爬虫』23. selenium之窗口切换与iframe(保姆级图文)

MZH 3768

Cy7c68013A速度测试教程

手里有一个cypress的CY7C68013A模块,一直没空玩。今天便测一下,这个模块的USB2.0速率。 1、开发工具下载 在cypress下载如下开发工具包(开发工具包下载地址) 2、驱动安装 一路Next即可 3、下载CyControl.exe 4、驱动安装 模块连接电脑,此时由于没有安装驱动,在设备管理器中显示未知设备...

LV9586的博客 5894

企业AI Agent的审计与合规

本文将带你从**“0基础理解企业AI Agent审计与合规”到核心概念梳理:用大白话+学术定义拆解什么是“企业AI Agent”、“可审计性(Auditability)”、“可解释性(Explainability,XAI)≠可审计性”、“合规性(Compliance)”、“黑盒拆解的三层维度”等硬核但必须掌握的概念;风险与合规背景:从**内部风险(数据泄露、误操作、模型偏差)和。

Java大师兄的博客 301

python selenium切换窗口_python3 selenium 切换窗口的几种方法

第一种方法:使用场景:打开多个窗口,需要定位到新打开的窗口使用方法:# 获取打开的多个窗口句柄windows = driver.window_handles# 切换到当前最新打开的窗口driver.switch_to.window(windows[-1])举例说明:# _._ coding:utf-8 _._""":author: 花花测试:time: 2017.05.03:content: 使用...

weixin_39612554的博客 1735

【AI+教育】别再让 Cursor 只当编辑器了!4 步解锁 Claude 官方技能!

本文介绍了在Windows环境下通过OpenSkills工具在Cursor中调用Claude AI技能的方法。主要内容包括:1)安装Node.js环境;2)全局安装OpenSkills工具;3)安装Claude官方技能库;4)通过AGENTS.md文件同步技能;5)在Cursor中直接调用技能完成Excel、PPT等任务。文章提供了详细的操作步骤和示例,帮助用户快速上手使用AI技能提升工作效率。

奶爸的编程之路,也就一周冷个三天 753

python如何切换windows窗口_python3 selenium 切换窗口的几种方法小结

第一种方法:使用场景:打开多个窗口,需要定位到新打开的窗口使用方法:# 获取打开的多个窗口句柄windows = driver.window_handles# 切换到当前最新打开的窗口driver.switch_to.window(windows[-1])举例说明:# _._ coding:utf-8 _._""":author: 花花测试:time: 2017.05.03:content: 使用...

weixin_39974557的博客 1982

数据库行转列的sql语句

 问题描述假设有张学生成绩表(CJ)如下Name Subject Result张三 语文 80张三 数学 90张三 物理 85李四 语文 85李四 数学 92李四 物理 82现在 想写  sql 语句     查询后结果 为    姓名 语文 数学 物理张三 80 90 85李四 85 92 82       该怎么实现 ?研究意义        这是个并不复杂的问题,但却是数

jb303的专栏 2248

网络调试和分析工具 Proxyman Premium

它支持MacOS、iOS和iPadOS等操作系统,提供丰富的功能,如查看和编辑HTTP/HTTPS请求和响应、设置断点、过滤请求等。Proxyman Premium还支持WebSocket、GraphQL和gRPC等现代网络协议调试,并通过直观且图形化的操作界面,使用户能高效地监控和操纵网络数据流。此外,它还具备多种高级功能,如WebSocket支持、DNS欺骗、自定义SSL证书等,为开发人员提供极大的便利。同时,由于软件版本更新和界面调整,上述步骤可能会有所变化,建议您参考最新版本的官方文档进行操作。

llhf688的博客 2001

机器人嵌入式岗位定价逻辑重写:STM32、RTOS与Linux技能溢价迁移

嵌入式系统开发中,实时操作系统与Linux内核的协同正成为机器人控制的核心技术栈。RTOS通过任务调度与资源隔离保障微秒级实时响应,而Linux凭借PREEMPT_RT补丁与多核异构架构,将AI推理与运动控制融合于同一计算平台。这种技术演进使系统级调试、多核通信与实时调优能力成为工程实践中的关键价值点,广泛应用于协作机器人、具身智能与工业自动化场景。在此背景下,STM32、RTOS与Linux的技能组合正在被重新定价,嵌入式工程师需从单机开发转向系统架构思维。

weixin_34355559的博客 463

银河麒麟V10离线安装VLC播放器:依赖处理与3.0.9.2版本实操指南

在国产化操作系统日益普及的背景下,软件安装方式成为政企内网用户关注的重点。离线安装作为一种不依赖公网源的部署手段,常用于解决内网环境下的软件获取问题。其核心在于理解Linux包管理机制,如dpkg与apt对依赖关系的处理逻辑。掌握这一原理,不仅能应对多媒体软件的部署,也能提升系统维护效率。VLC作为跨平台多媒体播放器,凭借强大的解码能力与协议支持,广泛应用于本地视频播放、RTSP拉流及监控大屏等场景。本文从离线安装的通用概念出发,结合银河麒麟V10桌面版的实际环境,详细梳理了VLC 3.0.9.2离线包的获

weixin_32247165的博客 371

python切换消息窗_python3 selenium 切换窗口的几种方法小结

第一种方法:使用场景:打开多个窗口,需要定位到新打开的窗口使用方法:# 获取打开的多个窗口句柄windows = driver.window_handles# 切换到当前最新打开的窗口driver.switch_to.window(windows[-1])举例说明:# _._ coding:utf-8 _._""":author: 花花测试:time: 2017.05.03:content: 使用...

weixin_39853968的博客 129

Allegro输出光绘文件规范

添加钻孔表的具体步骤为:1.通过屏幕右边的Visibility选项的Views列表,将Drill层打开2.将Visibility选项中的PIN和Via选项都选中,见下图所示: 参数设好之后关闭NC Drill/Parameters窗口,输出数控机床钻孔文件的命令菜单为:Manufacture=>NC=>NC Drill…,打开的窗口如下: 输出数控机床钻孔文件的具体步骤为: 上图是光绘输出的层控制窗口,还有一个窗口是输出参数的控制窗口,我们通过点击上图的第二个列表项General Parameters来

axingxiansen的博客 2808

AUTOSAR知识点 之 XCP (二):XCP基础概念

学习XCP的过程中,对XCP的基本概念要做一个全面的认知,因为里面有很多缩写以及难以理解的点,假设对此模模糊糊一知半解,那么对整个协议栈的认知会遇到极大的障碍。XCP的信号流传输图示如下XCP 标准主要分为 5 个部分:这部分提供了对于协议的一个概况介绍,包括 XCP 的功能和基础性内容。这部分内容对协议层进行了详细的规范和说明。

梦想技术家 2769

python123网页版切屏_python3 selenium 切换窗口的几种方法

第一种方法:使用场景:打开多个窗口,需要定位到新打开的窗口使用方法:# 获取打开的多个窗口句柄windows = driver.window_handles# 切换到当前最新打开的窗口driver.switch_to.window(windows[-1])举例说明:1 # _._ coding:utf-8 _._23 """4 :author: 花花测试5 :time: 2017.05.036 :...

weixin_39759182的博客 468

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

selenium切换窗口的几种方法小结

第一种方法 使用场景 打开多个窗口,需要定位到新打开的窗口; 使用方法: # 获取打开的多个窗口句柄 windows = driver.window_handles # 切换到当前最新打开的窗口 driver.switch_to.window(windows[-1]) 举例说明 # _._ coding:utf-8 _._ from selenium import webdriver impor...

daiyu__zz的博客 3万+

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

python如何切换windows窗口_selenium+python 切换窗口的几种方法

第一种方法:使用场景:打开多个窗口,需要定位到新打开的窗口使用方法:# 获取打开的多个窗口句柄windows = driver.window_handles# 切换到当前最新打开的窗口driver.switch_to.window(windows[-1])举例说明:from selenium import webdriverimport time# 打开百度主页【第一个窗口】driver = ...

weixin_39571403的博客 1652

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

python+selenium之窗口切换三种操作

window窗口切换有两种操作 窗口的切换有三种操作: 这里主要记录第二种稍微智能一点的操作,第一种在文章会在文章末尾给大家顺带提一下,注意:讲的是window窗口切换哦,不是html中的iframe面页切换,下次再给说iframe切换 在使用python+selenium操作页面元素时,会经常碰到点击某个元素弹出新的窗口,这是如果直接在新窗口操作元素肯定不行的,代码不是人类,我们的告诉它,要去另...

saber_sss的博客 4278

Selenium常用操作——打开多窗口和切换窗口

记录Selenium常用操作——打开多窗口和切换窗口

snailzzw的博客 8382

selenium窗口切换

说明:本篇博客基于selenium 4.1.0。

Tester_muller的博客 8769

python打开窗口切换_Python3 Selenium多窗口切换

Python3 Selenium多窗口切换以腾讯网(http://www.qq.com/)为例,打开腾讯网,点击新闻,打开腾讯新闻,点击新闻中第一个新闻链接。在WebDriver中封装了获取当前窗口句柄方法和获取所有窗口句柄的方法以及切换指定句柄窗口的方法;(句柄:英文handle,窗口的唯一识别码)方法:1). driver.current_window_handle --&g...

weixin_39549312的博客 280

Python +Selenium之(窗口切换操作、弹出对话框处理、获取当前窗口的title跟url)

1、切换窗口 在使用webdriver的时候,经常会遇到在多个窗口之间切换的操作,比如在A窗口操作某个元素,跳转到B窗口,然后又进入C窗口,此时这种情况就需要用到特殊的窗口处理方法 - [ ] 切换到新窗口里面的操作 循环遍历 deriver.window_handles driver.switch_to.wondow(handle)的方法切入新窗口 切换到最初的窗口 需要保存主窗口的handle 关闭窗口用 close 比如: 打开百度,输入周杰伦,点击链接打开新的窗口 from sele

wudada1993的博客 7104

Selenium之多窗口句柄的切换

前言 有些页面的链接打开后,会重新打开一个窗口,对于这种情况,想在新页面上操作,就得先切换窗口了。获取窗口的唯一标识用句柄表示,所以只需要切换句柄,我们就能在多个页面上灵活自如的操作了。 一、认识多窗口 1.打开赶集网:http://bj.ganji.com/,点击招聘求职按钮会发现右边多了一个窗口标签 2.我们用代码去执行点击的时候,发现界面上出现两个窗口,如下图这种情况就是多窗口了。 3.到这里估计有小伙伴纳闷了,手工点击是2个标签,怎么脚本点击就变成2个窗口了,这个之前讲...

专注自动化、性能测试、测试架构学习交流 8353
下一篇: 使用Cursor分析Jira数据实战指南(MCP配置版)
公子测试
博客等级 码龄10年 5粉丝 2原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值