Selenium RC For Python:教程5

來源:互聯網
上載者:User
 處理快顯視窗在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())

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.