How to open a new window or tab in webdriver (Python)?

后端 未结 4 2234
终归单人心
终归单人心 2021-01-06 11:49

I have tried various commands like

driver.switch_to_window(\"_blank\")

or

driver.switch_to_window(None)

b

4条回答
  •  猫巷女王i
    2021-01-06 12:11

    After tons of googling, I came across what works for me in Firefox and which is so simple (elegant, maybe?) as to be almost laughable. Here it is:

    >>> from selenium import webdriver
    >>> driver = webdriver.Firefox()
    >>> driver.execute_script("window.open('');")  <--- JAVASCRIPT!
    

提交回复
热议问题