zoukankan      html  css  js  c++  java
  • 2.7.2 元素定位:frame 内定位 driver.switch_to.frame()

    来源: http://blog.csdn.net/anniejunyan/article/details/23257327  Selenium + Webdriver 学习(五) frame下元素定位

              http://blog.csdn.net/huilan_same/article/details/52200586   selenium之 定位以及切换frame(iframe)

    frame标签有frameset、frame、iframe三种,frameset跟其他普通标签没有区别,不会影响到正常的定位。而frame与iframe对selenium定位而言是一样的,内部的元素都会不能直接定位到。

    driver.switch_to.frame(reference)

    driver.switch_to.parent_frame()        从子frame切回到父frame

    driver.switch_to.default_content()        切到frame中之后,我们便不能继续操作主文档的元素,这时如果想操作主文档内容,则需切回主文档。

    想要定位其中的iframe并切进去,可以通过如下代码:

    from selenium import webdriver
    driver = webdriver.Firefox()
    driver.switch_to.frame(0)  # 1.用frame的index来定位,定位第一个frame (index 下标从0开始)。
    # driver.switch_to.frame("frame1")  # 2.用id来定位
    # driver.switch_to.frame("myframe")  # 3.用name来定位
    # driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))  # 4.用WebElement对象来定位。即用find_element系列方法所取得的对象,我们可以用tag_name、xpath等来定位frame对象 
  • 相关阅读:
    ios开发之--把秒转换为天时分秒
    网络爬虫的类型
    网络爬虫的组成
    为什么要学网络爬虫
    什么是网络爬虫
    Windows 下安装 Python3
    Linux 下安装 Python3
    HTTP 代理
    HTTP Cookies
    爬虫的基本原理
  • 原文地址:https://www.cnblogs.com/ericazy/p/6894060.html
Copyright © 2011-2022 走看看