How to switch to new window in Selenium for Python?

后端 未结 5 1880
梦谈多话
梦谈多话 2020-11-22 13:16

I am working on selenium automation project using Python.

I am facing an issue, which is handling multiple browser windows.

Scenario is as f

5条回答
  •  遥遥无期
    2020-11-22 13:54

    We can handle the different windows by moving between named windows using the “switchTo” method:

    driver.switch_to.window("windowName")
    
    Click here to open a new window
    

    Alternatively, you can pass a “window handle” to the “switchTo().window()” method. Knowing this, it’s possible to iterate over every open window like so:

    for handle in driver.window_handles:
        driver.switch_to.window(handle)
    

提交回复
热议问题