zoukankan      html  css  js  c++  java
  • Selenium RC For Python:教程5

     处理弹出窗口
    在Selenium,弹出窗口是比较棘手的一个问题,下面谈谈利用Python怎么处理弹出窗口。
    最简单的方法:创建弹出窗口,然后使用get_all_window_names和select_window方法
    1. get_all_window_names(self):  Returns the names of all windows that the browser knows about.
    2. select_window(self,windowID): Selects a popup window using a window locator; once a popup window has been selected, all commands go to that window. To select the main window again, use null as the target.
    3. wait_for_pop_up(self,windowID,timeout): Waits for a popup window to appear and load up.
    4. select_window(self,windowID): Selects a popup window using a window locator; once a popup window has been selected, all commands go to that window. To select the main window again, use null as the target.
    5. close(self): Simulates the user clicking the "close" button in the titlebar of a popup window or tab.
    代码
        def test_popup_creation(self):
            sel 
    = self.selenium
            sel.open(self.TEST_PAGE_URL)
            sel.wait_for_page_to_load(self.MAX_WAIT_IN_MS)
            windowNames 
    = sel.get_all_window_names()
            
    #print windowNames[0]
            
            self.assertEquals(
    1, len(windowNames))
            self.assertEquals(
    "selenium_main_app_window", windowNames[0])
            
            sel.click(
    "link=This link opens a popup")
            sel.wait_for_pop_up(
    "popup", self.MAX_WAIT_IN_MS)
            windowNames 
    = sel.get_all_window_names()
            
    print windowNames
            
            self.assertEquals(
    2, len(windowNames))
            self.assertTrue(
    "selenium_main_app_window" in windowNames)
            self.assertTrue(
    "popup" in windowNames)

    关闭弹出窗口,回到最初的窗口

             # close popup

            sel.close()

            

            # select original window

            sel.select_window("null")

    代码
        def test_window_selection_closepopup_returntomainwindow(self):
            sel 
    = self.selenium
            sel.open(self.TEST_PAGE_URL)
            sel.wait_for_page_to_load(self.MAX_WAIT_IN_MS)
            self.assertEquals(self.TEST_PAGE_TITLE, sel.get_title())
            
            sel.click(
    "link=This link opens a popup")
            sel.wait_for_pop_up(
    "popup", self.MAX_WAIT_IN_MS)
            sel.select_window(
    "popup")
            self.assertEquals(
    "Bit Motif", sel.get_title())
            
            
    # close popup
            sel.close()
            
            
    # select original window
            sel.select_window("null")
            self.assertEquals(self.TEST_PAGE_TITLE, sel.get_title())
    作者:Shane
    出处:http://bluescorpio.cnblogs.com
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    Python time ctime()方法
    Python time clock()方法
    Python time asctime()方法
    Python time altzone()方法
    Python 日期和时间
    java——字符串常量池、字符串函数以及static关键字的使用、数组的一些操作函数、math函数
    java——API
    java——类、对象、private、this关键字
    Java——方法及构造方法、intellij IDEA中的一些快捷键
    IntelliJ IDEA 运行java程序时出现“程序发生找不到或无法加载主类 cn.test1.test1”错误
  • 原文地址:https://www.cnblogs.com/bluescorpio/p/1744002.html
Copyright © 2011-2022 走看看