java - How to throw exception when i have open two or three windows -
java - How to throw exception when i have open two or three windows -
i have 2 or 3 open (in different cases) windows , trying throw exception start next test. when write:
throw new runtimeexception("anything"); the new popup window show text: "the webpage viewing trying close window. want close window" , script stop.
browser: net explorer 8 know, window shows when seek close window.
ok, add together code:
//my methods public static boolean switchtowindowabouttitle(webdriver driver, string title){ string currentwindow = driver.getwindowhandle(); set<string> availablewindows = driver.getwindowhandles(); try{ if(!availablewindows.isempty()){ for(string windowid : availablewindows){ string switchedtitle = driver.switchto().window(windowid).gettitle(); if(switchedtitle.equals(title) || switchedtitle.contains(title)) homecoming true; else{ driver.switchto().window(currentwindow); } } } }catch(nosuchwindowexception ignore){ homecoming false; } homecoming false; } //my code: //my main window -- window title: "main" driver.switchto().defaultcontent(); driver.switchto().frame("main"); //click on button open new window driver.findelement(bydeterminebutton).click(); //window title: "authorize" switchtowindowabouttitle(driver, "authorize"); new webdriverwait(driver, 180).until(expectedconditions.elementtobeclickable(byproduct)); driver.findelement(byproduct).click(); seek { thread.sleep(10000); } grab (interruptedexception e) { // todo auto-generated grab block e.printstacktrace(); } system.out.println(driver.getwindwhandles().size()); //show 3 //after click when window size == 3 i'd throw exception because means product isn't available --> 3rd window show info it. if(driver.getwindowhandles().size() == 3){ throw new runtimeexception("test"); } when execute code: throw new runtimeexception("test"); net explorer show alert: "the webpage viewing trying close window. want close window?" , have 2 options: yes or no.
why can't throw exception :(
java selenium
Comments
Post a Comment