Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Selenium Learning: switching between multiple forms

Shulou Source: shulou.com Published: 2022-06-03 05:33:21 11月24日 Update

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()

Tags: Switch file form can be passed properties methods positioning learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information vpn OPPO Reno NVidia