Open and close new tab with Selenium WebDriver in OS X

前端 未结 5 565
北恋
北恋 2021-01-11 16:23

I\'m using the Firefox Webdriver in Python 2.7 on Windows to simulate opening (Ctrl+t) and closing (Ctrl + w) a new tab.

5条回答
  •  [愿得一人]
    2021-01-11 16:51

    You can choose which window you want to close:

    window_name = browser.window_handles[0]
    

    Switch window:

    browser.switch_to.window(window_name=window_name)
    

    Then close it:

    browser.close()
    

提交回复
热议问题