How can I close a specific window using Selenium WebDriver with Java?

后端 未结 4 789
耶瑟儿~
耶瑟儿~ 2021-01-03 21:27

I use Selenium WebDriver. I open the first page then open the second page - perform some action and go back to first page. Before I want to close the second page I use the c

4条回答
  •  遥遥无期
    2021-01-03 22:08

    In Python

    default_handle = driver.current_window_handle
    handles = list(driver.window_handles)
    assert len(handles) > 1
    
    handles.remove(default_handle)
    assert len(handles) > 0
    
    driver.switch_to_window(handles[0])
    # do your stuffs
    driver.close()
    driver.switch_to_window(default_handle)
    

提交回复
热议问题