当前位置:网站首页>框架跳转导致定位失败的解决方法
框架跳转导致定位失败的解决方法
2022-06-26 08:30:00 【冯大少】
相信大多数的Selenium初学者都会遇到莫名其妙的定位的element找不到的报错,其实除了人为的粗心写错语法、属性值、又或者还没有等待所需要定位的element在页面加载完成外,主要原因是框架跳转和超链接跳转的问题。
关于超链接跳转的多窗转换,这里就不再重复介绍,详细可用看我之前博客的测试文章。如下图,在登录后,例如“企业网站”的 “去管理”这个超链接的 label,是在 iframe这框架里,所以在定位前,必须先跳转到这个框架里。由于该网站对所有超链接都是用 js 去隐藏达到反爬目的,因此在我们定位点击后,就会自动打开新的标签页,然后通过窗口转换,就可以爬取相对应的 URL 。
在自动化测试中,除了要熟练掌握定位之外,还需要掌握前端的通过 js 对 各种 element attribution value 的 增、删、改方法。相关的方法可以参考我之前的博客。
browser.switch_to_frame('mainFrame')
link = browser.find_element_by_link_text('去管理>')

边栏推荐
猜你喜欢

Degree of freedom analysis_ nanyangjx

Relation extraction model -- spit model

(4) Independent key

STM32 project design: temperature, humidity and air quality alarm, sharing source code and PCB

FFmpeg音视频播放器实现

SOC wireless charging scheme

And are two numbers of S

三菱PLC若想实现以太网无线通讯,需要具备哪些条件?

What is Qi certification Qi certification process

(1) Turn on the LED
随机推荐
Use of PCL
QT_ AI
ZLMediaKit推流拉流测试
Zlib static library compilation
Convert verification code image to tfrecord file
Embedded Software Engineer (6-15k) written examination interview experience sharing (fresh graduates)
Leetcode: array fast and slow pointer method
Performance comparison of unaryexpr's function on matrix elements in eigen Library
Learning signal integrity from scratch (SIPI) -- 3 challenges faced by Si and Si based design methods
【Unity Mirror】NetworkTeam的使用
[已解决]setOnNavigationItemSelectedListener()被弃用
软件工程-个人作业-提问回顾与个人总结
What are the conditions for Mitsubishi PLC to realize Ethernet wireless communication?
鲸会务为活动现场提供数字化升级方案
Tensorboard
Record the problem yaml file contains Chinese message 'GBK' error
Relationship extraction -- casrel
Design of reverse five times voltage amplifier circuit
Digital image processing learning (II): Gaussian low pass filter
Monitor iPad Keyboard Display and hide events