当前位置:网站首页>框架跳转导致定位失败的解决方法
框架跳转导致定位失败的解决方法
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('去管理>')

边栏推荐
猜你喜欢

Exploration of webots and ROS joint simulation (I): software installation

Koa_ mySQL_ Integration of TS

MPC learning notes (I): push MPC formula manually

Principle of playing card image segmentation

Fourier transform of image

Opencv learning notes II

Whale conference provides digital upgrade scheme for the event site

(4) Independent key

Learn signal integrity from zero (SIPI) - (1)

2020-10-17
随机推荐
Comparison between Apple Wireless charging scheme and 5W wireless charging scheme
Transformers loading Roberta to implement sequence annotation task
Application of wireless charging receiving chip xs016 coffee mixing cup
Design based on STM32 works: multi-functional atmosphere lamp, wireless control ws2812 of mobile app, MCU wireless upgrade program
SQL learning experience (II): question brushing record
OpenGL display mat image
Google Chrome collection
Clion installation + MinGW configuration + opencv installation
Swift code implements method calls
(4) Independent key
Text to SQL model ----irnet
VS2005 project call free() compiled with static libcurl library reported heap error
Assembly led on
Speckle denoising method for ultrasonic image
STM32 project design: an e-reader making tutorial based on stm32f4
Steps for ROS to introduce opencv (for cmakelist)
WBC learning notes (II): practical application of WBC control
Digital image processing learning (II): Gaussian low pass filter
I Summary Preface
Stream analysis of hevc learning