In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you "selenium how to locate multiple nested iframe", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "selenium how to locate multiple nested iframe" this article.
one。 Driver.switch_to.frame (id): you can switch to iframe via id
I learned how to switch from selenium to iframe before, and the code is as follows
From selenium import webdriverdriver = webdriver.Chrome () driver.switch_to.frame (0) # 1. Using the index of frame to locate, the first one is locate driver.switch_to.frame ("frame1") # 2. Use id to locate # driver.switch_to.frame ("myframe") # 3. Use name to locate # driver.switch_to.frame (driver.find_element_by_tag_name ("iframe")) # 4. Use WebElement objects to locate
The source code does not say that it can be located through id, but in fact it can.
It is important to note that for juxtaposed iframe, we can use subscript, but nested ones are not allowed except the first one can be represented by subscript 0.
# juxtaposed iframeiframe-- subscript 0 | iframe-- subscript 1 | iframe-- subscript "nested iframeiframe- -- id= "F1" iframe-- id= "f2" iframe-- id= "f3" 2. Through id location # first find iframe1 (id= "F1") driver.switch_to.frame ("F1") # and then find the iframe2 (id= "f2") driver.switch_to.frame ("f2") below it
Perfect solution, there is another problem, we have to cut to the superior iframe, how to achieve
3. Cut from the child iframe to the parent iframe
Selenium provides a similar "fallback" method, as follows
Driver.switch_to.parent_frame () # has no effect if it is currently the main document. Summary
At present, there are three main methods for iframe processing.
1 driver.switch_to.frame (reference) 2 driver.switch_to.parent_frame () 3 driver.switch_to.default_content ()
There are four switching parameters for the first kind of iframe: idex, id, name, and webelement.
The above is all the content of the article "how selenium locates multiple nested iframe". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.