Selenium Learning: switching between multiple forms
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()