How to open a new window on a browser using Selenium WebDriver for python?

后端 未结 4 887
谎友^
谎友^ 2020-12-05 19:10

I am attempting to open a new tab OR a new window in a browser using selenium for python. It is of little importance if a new tab or new window is opened, it is only import

4条回答
  •  醉梦人生
    2020-12-05 19:47

    I recommend to use CTRL + N command on Firefox to reduce less memory usage than to create new browser instances.

    import selenium.webdriver as webdriver
    from selenium.webdriver.common.keys import Keys
    
    browser = webdriver.Firefox()
    body = browser.find_element_by_tag_name('body')
    body.send_keys(Keys.CONTROL + 'n')
    

    The way to switch and control windows has already been mentioned by Dhiraj.

提交回复
热议问题