Selenium +python how to get a popup window

Source: Internet
Author: User

capturing or positioning. pop-up windowThe key is to get a handle to the popup window. I still like to illustrate by example: #-*-coding=utf-8from Selenium Import WebdriverImport Unittest class Login (unittest. TestCase):    def setUp (self):        Self.driver = Webdriver. Firefox ()         self.driver.implicitly_wait (+)         Self.base_url = "/http" Www.baidu.com "        self.verificationerrors = []        def test_ Loginpass (self):        Driver = self.driver        Driver.get (Self.base_url) & nbsp       nowhandle=driver.current_window_handle# here to get the current window handle         Driver.find_ element_by_id ("kw"). Send_keys ("Selenium")         driver.find_element_by_id ("su"). Click ()         Driver.find_element_by_xpath ("//a[@title = ' Selenium installation ']"). Click ()         aalhandles=driver.window_handles# get all window handles         for handle in Aalhandles: #在所有窗口中查找弹出窗口             if Handle!=nowhandle:                Driver.switch_to_window (handle) #这两步是在弹出窗口中进行的操作 to prove that we did enter the                 Driver.find_element_by_link_text ("News"). Click ()     & nbsp   Driver.switch_to_window (nowhandle) #返回到主窗口页面         driver.find_element_by_id ("kw"). Clear () #下面三步是返回到主窗口中进行的操作, proving that we did return         driver.find_element_by_id ("kw"). Send_keys (" python") driver.find_element_by_id (" su "). Click () def tearDown (self): #self. Driver.quit () self.as Sertequal ([], self.verificationerrors) if __name__ = = "__main__": Unittest.main () Note: Webdriver in Python Curren T_window_handle to get the current window function window_handles get all the window functions Switch_to_window () into the specified window function

Selenium +python how to get a popup window

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.