简体   繁体   English

硒:测试弹出窗口

[英]Selenium: Testing pop-up windows

I have an issue when trying to test a web application with Selenium/Python. 尝试使用Selenium / Python测试Web应用程序时遇到问题。 Basically I can't test elements of a pop-up window. 基本上,我无法测试弹出窗口的元素。

A scenario: I can test all elements for a page. 一个场景:我可以测试页面的所有元素。 But when I go to click on a button that opens up a small pop up box I can't test the elements on the popup. 但是,当我单击打开一个小的弹出框的按钮时,我无法测试弹出框上的元素。 It's like the pop up isn't in focus or active. 就像弹出窗口没有聚焦或处于活动状态一样。

I can test elements on the next page. 我可以在下一页上测试元素。 For example click a button, brings me on to next page, and I can work with elements on the 'next' page. 例如,单击一个按钮,将我带到下一页,然后我可以处理“下一页”页面上的元素。 So it the problem seems to be popup specific. 因此,问题似乎是特定于弹出窗口的。

I could post code but to be honest it might confuse at this stage. 我可以发布代码,但老实说,在现阶段可能会造成混淆。 I may post code in a later post, thanks 我可能会在以后的帖子中发布代码,谢谢

There is a property called switch_to 有一个名为switch_to的属性

Q: How do I handle pop up windows? 问:如何处理弹出窗口?

A: WebDriver offers the ability to cope with multiple windows. 答:WebDriver提供了处理多个窗口的功能。 This is done by using the WebDriver.switch_to.window(knownName) method to switch to a window with a known name. 这是通过使用WebDriver.switch_to.window(knownName)方法切换到具有已知名称的窗口来完成的。

If the name is not known, you can use WebDriver.window_handles to obtain a list of known windows. 如果名称未知,则可以使用WebDriver.window_handles获取已知窗口的列表。

You may pass the handle to switch_to.window(handleName) 您可以将句柄传递给switch_to.window(handleName)

For example I used driverName.switchTo.window(driverName.getWindowHandle()) to get a hold of popups for which I didn't want to look for names. 例如,我使用driverName.switchTo.window(driverName.getWindowHandle())获得了一些我不想为其查找名称的弹出窗口。

Additional references: http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions 其他参考: http : //code.google.com/p/selenium/wiki/FrequentlyAskedQuestions

For the Selenium RC API, you need to use the SelectWindow command to switch to the pop-up window. 对于Selenium RC API,您需要使用SelectWindow命令切换到弹出窗口。 The window can be specified either by its name (as specified on the JavaScript window.open() function) or its title. 可以通过窗口的名称(在JavaScript window.open()函数中指定)或窗口的标题来指定窗口。 To switch back to the main window, use SelectWindow(None) . 要切换回主窗口,请使用SelectWindow(None)

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

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