selenium 切换多个表单iframe

selenium 切换多个表单iframe

from selenium import webdriver
import os,time
driver = webdriver.Firefox()
fire_path = 'file:///' + os.path.abspath('frame.html') #调用本地的文件
driver.get(fire_path)
#如果页面有多个frame表单,该如何切换呢
driver.switch_to_frame('if') #可以直接写表单id或name
xp = driver.find_element_by_xpath('///iframe[@id="if"]') #使用xpath切换iframe
driver.switch_to_frame(xp) #使用xpath切换iframe

#定位元素,进行操作
driver.find_element_by_id("kw").click()

#表单退出到最外层
switch_to_default_content()
#返回上一级表单
driver.switch_to_parent_content()

 

相关文章:

  • 2021-08-17
  • 2021-10-15
  • 2021-11-19
  • 2021-11-25
  • 2021-04-22
  • 2021-09-01
  • 2022-01-04
  • 2021-05-04
猜你喜欢
  • 2022-02-25
  • 2021-12-12
  • 2021-08-23
  • 2021-12-13
  • 2021-05-06
  • 2021-12-07
  • 2021-10-03
相关资源
相似解决方案