WebDriver-多表单切换

"""
web中经常遇到frame/iframe表单嵌套页面的应用,WebDriver只能在一个页面上对元素识别与定位,对于内嵌页面无法定位识别到。
需要使用到switch_to.frame()方法将当前定位主体切换到内嵌页面上。
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import os
driver = webdriver.Chrome()
file_path = 'file:///' + os.path.abspath('frame.html')
driver.get(file_path)

# 切换到iframe:嵌套的csdn页面
driver.switch_to.frame("iframe01")

# 对嵌套的csdn页面进行搜索操作
driver.find_element(By.ID, "toolbar-search-input").send_keys("python知多少?")
driver.find_element(By.ID, "toolbar-search-button").click()
time.sleep(3)
driver.quit()

WebDriver-多表单切换


#frame.html代码


    
    frame or iframe
    
    

    
    
        
            

frame

展开阅读全文

页面更新:2024-04-18

标签:表单   嵌套   主体   元素   页面   代码   操作   方法

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top