简体   繁体   English

硒中的窗口处理(python)

[英]window handling in selenium (python)

My simple script written in python (selenium) need to click on number of hyperlinks (around 25) in a single web page, each time need to assert something in a new window opened. 我用python(硒)编写的简单脚本需要单击单个网页中的超链接数(约25个),每次都需要在打开的新窗口中声明某些内容。

I am using the following function to navigate between the windows, which also works well. 我正在使用以下功能在两个窗口之间导航,效果也很好。

def go_window(self, window_name = None):
    if window_name is None:
        self.driver.switch_to_window(self.window_handle)
    else:
        self.driver.switch_to_window(window_name)

However, it does not close the new window opened each time (also because, links in my page open up the new page each time it is clicked :( ). 但是,它不会关闭每次打开的新窗口(也因为每次单击:()时,页面中的链接都会打开新页面。

I would want to close the new window after asserting. 我想断言后关闭新窗口。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

使用WebDriver.close方法,它将关闭当前窗口:

self.driver.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM