我有web应用程序,如果从下拉列表中选择值,则弹出窗口将打开。
现在我想使用selenium Webdriver访问弹出的元素你可以帮助我吗,我曾经尝试过driver.switchTo().window(WindowHandle)
,但你不能帮助我做这个...
new Select(driver.findElement(By.id("selector"))).selectByVisibleText("text");
String handle1 = driver.getWindowHandle();
driver.switchTo().window(handle1);
答案 0 :(得分:0)
Set<String> pops=Driver.getWindowHandles();
Iterator<String> it =pops.iterator();
while (it.hasNext()) {
String popupHandle=it.next().toString();
System.out.println("Driver Now switched to Pop Up with Title- "+ Driver.switchTo().window(popupHandle).getTitle());
}
}
答案 1 :(得分:0)
请使用我在其他评论中复制的上述Html代码
公共类PopupWindow
{
public WebDriver driver;
String parentWindow,childWindow;
@Before
public void setUp()
{
driver=new FirefoxDriver();
driver.get("file:///C:/Users/vkiran/Desktop/select.html");
}
@Test
public void popupTest()
{
Select dropwdown=new Select(driver.findElement(By.xpath("//select[@id='myURLs']")));
dropwdown.selectByVisibleText("News");
Set <String> handles =driver.getWindowHandles();
Iterator<String> it = handles.iterator();
while (it.hasNext())
{
parentWindow=it.next();
childWindow=it.next();
}
driver.switchTo().window(childWindow);
driver.close();//closing pop window
driver.switchTo().window(parentWindow);//switch back to parent window
driver.quit();//close current active window which is parent
}
}
答案 2 :(得分:0)
<html>
<head>
<title>Pop URL on Select</title>
<script language="JavaScript" type="text/javascript">
function openPop()
{
var Sel_Ind = document.getElementById('myURLs').selectedIndex;
var popUrl = document.getElementById('myURLs').options[Sel_Ind].value;
winpops=window.open(popUrl,"","width=400,height=338,resizable,")
}
</script>
</head>
<body>
<select id="myURLs" onChange="javascript:openPop();">
<option value="">Select a page...</option>
<option value="http://www.bbc.co.uk">News</option>
<option value="http://www.yahoo.com">Music</option>
<option value="http://www.google.com">Laughs</option>
<option value="http://www.google.com">Search</option>
<option value="http://www.google.com">Help</option>
</select>
</body>
</html>