public void projectlinks() throws Exception{
jsClick(getWebElement("project.landingPage.linkedIn"));
String Exp_titleL = "LinkedIn: Log In or Sign Up";
jsClick(getWebElement("project.landingPage.twitter"));
String Exp_titleT = "project (@project_app) | Twitter";
jsClick(getWebElement("project.landingPage.facebook"));
String Exp_titleF = "project - Home | Facebook";
jsClick(getWebElement("project.landingPage.googleplus"));
String Exp_titleG = "project app - Google+";
jsClick(getWebElement("project.landingPage.instagram"));
String Exp_titleI = "project (@project_app) • Instagram photos and videos";
String originalWindowHandle = driver.getWindowHandle();
java.util.Set<java.lang.String> windowHandles = driver.getWindowHandles();
for (String window: windowHandles) {
if(!window.equals(originalWindowHandle)){
driver.switchTo().window(window);
Thread.sleep(5000);
String title = driver.getTitle();
System.out.println("current title is: " + title);
if(title.equals(Exp_titleT) ){
System.out.println("Directed to project Twitter page - success");
}else if(title.equals(Exp_titleF)){
System.out.println("Directed to project Facebook page - success");
}else if(title.equals(Exp_titleG)){
System.out.println("Directed to project Google+ page - success");
}else if(title.equals(Exp_titleI)){
System.out.println("Directed to project Instagram page - success");
}else if(title.equals(Exp_titleL)){
System.out.println("Directed to project LinkedIn page - success");
}else{
System.out.println("Fail - Failed to reirect");
}
}
}
结果:
Directed to project LinkedIn page - success
Directed to project Twitter page - success
Directed to project Facebook page - success
Directed to project Google+ page - success
问题:所有链接都被点击但无法获得最后一个窗口标签'Instagram'标题