c# - Selenium WindowHandles not detect all opened popups -


i'm trying switch between 2 opened popups. driver.windowhandles return 1 handle(id). don't know how switch second popup. command driver.switchto().activeelement doesn't work.

readonlycollection<string> currenthandleslist = driver.windowhandles; console.writeline(currenthandleslist.count); 

result of : 1

why returns 1. why not 2 ?

thanks lot.

you should use below approach :-

string currenthandle = driver.currentwindowhandle; //save currently-focused window handle variable can switch later.  readonlycollection<string> originalhandles = driver.windowhandles; //get list of opened window handles.  // work here open popups  // webdriverwait.until<t> waits until delegate return popup window handle. webdriverwait wait = new webdriverwait(driver, timespan.fromseconds(5));  string popupwindowhandle = wait.until<string>((d) => {     string foundhandle = null;      // subtract out list of known handles. in case of single     // popup, newhandles list have 1 value.     list<string> newhandles = driver.currentwindowhandles.except(originalhandles).tolist();     if (newhandles.count > 0)     {         foundhandle = newhandles[0];     }      return foundhandle; });  driver.switchto().window(popupwindowhandle);  // whatever need on popup browser, then... driver.close(); driver.switchtowindow(currenthandle); 

in way can work popups.. hope you..:)


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -