从POP上窗切换到原始窗口selenium python

时间:2014-06-24 11:32:41

标签: python-2.7 selenium-webdriver

我正在使用下面的代码。在第0行我调用了我的网站网址,第1行我点击图像打开弹出窗口(第2次IE会话)然后我使用第3,4,5,6行处理弹出窗口 在弹出IE之后,我做了一些工作,比如提供名称为alpha。

现在我的问题是我必须关闭这个弹出窗口(第二个IE会话)并且焦点需要打开我的第一个IE i,e到行0,1 UI。 这怎么可能?

0            self.driver.get(url[0]+"abc.com")
1            self.driver.find_element_by_css_selector("input[type=\"image\"]").click()
2            time.sleep(15)
3            parent_h = self.driver.current_window_handle
4            handles = self.driver.window_handles # before the pop-up window closes
5            handles.remove(parent_h)
6            self.driver.switch_to_window(handles.pop())
7        self.driver.find_element_by_id("name").clear()
8           self.driver.find_element_by_id("name").send_keys(alpha)

1 个答案:

答案 0 :(得分:0)

你已经拥有它:

self.driver.close()
self.driver.switch_to_window(parent_h)
相关问题