Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Selenium Learning: switching between multiple forms

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

File: frame.html

$(document).ready(function(){});> frame

File: test11.py

from selenium import webdriver

import os,time

driver = webdriver.Chrome()

file_path='file:///'+os.path.abspath('frame.html')

driver.get(file_path)

#Because iframe is used, embedded, so switch to iframe (id="if")

from selenium import webdriverimport os,timedriver = webdriver.Chrome()file_path ='file://'+ os.path.abspath ('frame.html') driver.get(file_path)#Switch to iframe (id="if") driver.switch_to.frame("if")time.sleep(3)driver.find_element_by_id("kw").send_keys("selenium")driver.find_element_by_id("su").click()time.sleep(3)driver.quit()

swith_to_frame() directly obtains the id or name attribute of the form by default. If the iframe has no id or name available, it can be located by the following methods:

xf=driver.find_element_by_path('//*[@class="if"]')driver.switch_to.frame(xf)driver.switch_to_.parent_frame()

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report