zoukankan      html  css  js  c++  java
  • Python3---selenium---frame切换

    Python3---selenium---frame切换

    2020-04-10

      frame元素或iframe元素是一个特殊的元素,会包含一个被嵌入的另一份html文档。我们使用selenium打开一个网页,缺省的位置是当前html。并不包含被嵌入的html文档里面的内容。所以我们需要切换到iframe元素当中。

      切换某iframe元素:switch_to.frame(‘frame_reference’) 

      注释:frame_reference 可以是frame元素的属性name 或者 ID,也可以是WebElement对象。(比如:driver.switch_to.frame(driver.find_element_by_tag_name('iframe'))

      切换回主html:switch_to.default_content()

    E.g

    from selenium import webdriver
    
    driver = webdriver.Chrome('D:chromedriver_win32chromedriver.exe')
    
    driver.get('http://cdn1.python3.vip/files/selenium/sample2.html')
    
    #selenium 操作范围缺省是当前的html。切换到iframe操作范围
    print('iframe页面搜索内容:')
    driver.switch_to.frame('frame1')
    driver_title = driver.find_elements_by_tag_name('div')
    for i in driver_title:
        print(i.text)
    print('*******************************************************')
    print('主页面搜索内容:')
    #切换为主html
    driver.switch_to.default_content()
    driver_title = driver.find_elements_by_tag_name('div')
    for i in driver_title:
        print(i.text)
    driver.close()

     

  • 相关阅读:
    session的生命周期
    临远的spring security教程
    spring security原理图及其解释
    解决eclipse中出现Resource is out of sync with the file system问题
    从SOA到BFV【普元的一份广告文章】
    普元OA平台介绍
    门户平台
    企业门户平台解决方案
    使用 CAS 在 Tomcat 中实现单点登录
    CAS 跨域原理
  • 原文地址:https://www.cnblogs.com/aaron456-rgv/p/12673409.html
Copyright © 2011-2022 走看看