Selenium-webdriver系列教程(6)————如何捕获弹出窗口
在web自动化测试中点击一个链接然后弹出新窗口是比较司空见惯的事情。
webdriver中处理弹出窗口跟处理frame差不多,以下面的html代码为例
window.html<html> <head><title>Popup Window</title></head> <body> <a id = "soso" href = "http://www.soso.com/" target = "_blank">click me</a> </body></html>
require 'rubygems'require 'pp'require 'selenium-webdriver'dr = Selenium::WebDriver.for :firefoxframe_file = 'file:///'.concat File.expand_path(File.join(File.dirname(__FILE__), 'window.html'))dr.navigate.to frame_filedr.find_element(:id =>'soso').click# 所有的window handleshs = dr.window_handles# 当前的window handlech = dr.window_handlepp hspp ch hs.each do |h| unless h == ch dr.switch_to.window(h) p dr.find_element(:id => 's_input') endend