how to verify the title of a newly window open and once i verified then close the opened new window?
so in my page I have a link and click on the link and it opens a new window and now I am not sure how to verify the title of that window.
here is what i have done so far.
GoToMysiteUrl();
IWebElement addtoList = driver.FindElement(By.XPath(_pageName));
addtoList.Click();
//it opens a new window
now i want to switch focus on the new window and verify the title and close the new window back to the previous window.
Hello Abu,
Assalamu alaaikkum...
This is very much possible in Selenium Webdriver...One thing you need to know here is when your selenium webdriver starts a session and opens a browser loading your URL, that browser window will be the parent window... so driver control/focus will be always on that parent window...
Now as you mentioned ,when you click on a link on this parent browser it results in opening a new window ... so this newly opened window we can call it as a child window... And remember the Selenium webdriver control is still in your parent window and not on this newly opened child window... so you wont be able to do any action on this child window... this is the problem you facing here...
This can be solved by switching the driver control to your child window.. and this can be achieved as follows :
WebDriver provides a function called .getWindowHandles();... this gets the window handles for all the window getting opened by your test actions .... and this function returns a Set of Strings... and by code it will look like
set <String > allwindowhandles= driver.getWindowHandles();
allwindowhandles is just a variable here ...
Use a java logic of Iterator to capture all the windowhandles , like here parent and child window handles....
Iterator<String> itr = allwindowhandles.Iterator();
String parentwindow = itr.next();
String childwindow = itr.next();
now use the function called .SwitchtoWindow(childwindow).. to move the driver focus to the second opened window...
and you can do the action on that window,like verifying the tile and all.... as your testing needs
Now if you want to close the second opened window and move back to the parent window.. you should do similat steps ... by close command and switching the driver control.... :)
Hope this helps ... and you may have to convert the logic to C#...(i have no clue on C#)/.... :)
~Musaffir
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/8bHiKSZvXmoJ.--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.