zoukankan      html  css  js  c++  java
  • 通过名称识别和处理弹出窗口

     1 # -*- coding:utf-8 -*-
     2 """
     3 switch_to_window():接受 name 和  handle 属性
     4 name 属性和它的 title 是不一样的
     5 如下例子中的 name 为: HelpWindow
     6 <html>
     7     <head>
     8         <title>help</title>
     9     </head>
    10     <body>
    11         <button id="helpbutton1" onclick="window.open("PopUpWindow.html","HelpWindow","width=500,height=500");">Help1</button>
    12         <button id="helpbutton2" onclick="window.open("PopUpWindow.html","HelpWindow","width=500,height=500");">Help2</button>
    13     </body>
    14 </html>
    15 """
    16 from selenium import webdriver
    17 
    18 driver = webdriver.Firefox()
    19 driver.get(r'F:电子书seleniumSelenium Testing Tools Cookbook(中文)demowindow.html')
    20 
    21 #父窗口句柄
    22 parentWindowId = driver.current_window_handle
    23 
    24 driver.find_element_by_id('helpbutton1').click()
    25 
    26 #转到 HelpWindow窗口
    27 driver.switch_to_window('HelpWindow')
    28 
    29 print driver.title
    30 
    31 assert 'PopUpWwindow', driver.find_element_by_tag_name('p').text
    32 
    33 #关闭子窗口
    34 driver.close()
    35 
    36 #回到父窗口
    37 driver.switch_to_window(parentWindowId)
    38 
    39 #验证父窗口的title
    40 assert True, driver.title == 'help'
    41 
    42 driver.close()
  • 相关阅读:
    log4j 悟寰轩
    初学PHP 悟寰轩
    java基本语法注意问题 悟寰轩
    HTTP协议基础 悟寰轩
    SSHweb.xml详解 悟寰轩
    windows和linux查找被入侵后留下的后门文件 悟寰轩
    MFC Link problem
    Manually Walking a Stack
    linux试用(2)安装 mplayer, g++
    子集和问题
  • 原文地址:https://www.cnblogs.com/Roger1227/p/3176394.html
Copyright © 2011-2022 走看看