zoukankan      html  css  js  c++  java
  • Python_selenium之窗口切换

    Python_selenium之窗口切换

    1. 运用switch_to.window()方法来进行窗口切换

    2. 思路拆分:

    1. 浏览器获取百度贴吧网址
    2. 点击定位到一个元素,获取当前的句柄
    3. 获得所有的句柄信息
    4. 用for语句进行遍历,若没有找到,则关闭之前打开的窗口并且切换窗口

    3. 测试脚本如下:

    #coding:utf-8

    from selenium import webdriver

    driver=webdriver.Chrome()

    driver.maximize_window()

    driver.implicitly_wait(8)

    driver.get("http://news.baidu.com/")

    driver.find_element_by_xpath("//*[@id='pane-news']/div/ul/li/strong/a[contains(text(),'牢记使命 永远做草原上的“红色文艺轻骑兵”')]").click()

    print driver.current_window_handle #输出当前窗口句柄

    handles=driver.window_handles #输出当前所有句柄

    print handles

    for handle in handles:

        if handle != driver.current_window_handle:

            print "switch to second window",handle

            driver.close()

            driver.switch_to.window(handle)

    4. 上述运用的是谷歌浏览器进行测试的,但是我运用火狐浏览器时,窗口并没有关闭

  • 相关阅读:
    hbase 简介
    Hadoop本地库介绍
    MapReduce:详解Shuffle过程
    eucalyptus,openstack
    openstack installing...
    今年2011
    wget代理设置(转载)
    openstack running
    python 升级到2.6(转载)
    高德地图Windowphone API学习地图定位与地图模式的切换
  • 原文地址:https://www.cnblogs.com/Rita-LJ/p/7885939.html
Copyright © 2011-2022 走看看