c# - Selenium: When a page is open in a new tab, is it possible to keep testing in the new page? -
i'm testing menu on page using selenium , c# webdriver. when clicked, each of menu items opens page in new google chrome. wonder whether there way continue testing in new chrome tab has been openned.
thank helping.
yes, possible test on new pages opened current window.
suppose clicking on menu, opens page in new window. driver object have access current page , newly opened page in form of window handle(or window id). can window handles , switch driver control page using handle.
to current window handle driver has control of, can use
string currentwindowhandle= driver.getwindowhandle(); this returns handle current window uniquely identifies within driver instance. can used switch current window @ later stage.
to window handles driver can have access to, use
set<string> allwindowhandles=driver.getwindowhandles(); this returns set of window handles can used iterate on open windows.
then iterate set
iterator iter = allwindowhandles.iterator(); while (iter.hasnext()) { string windowhandle=iter.next();//get window handle set system.out.println(windowhandle);//this print uique window handle id driver.switchto().window(windowhandle);// switch driver control window having handle id. // window title or url etc. , check whether matches expected page title. //if yes, have navigated correct page , can continue working on page. if(driver.gettitle().equals("new menu page title")) //then break loop have got required page access. break; }
Comments
Post a Comment