Skip to main content

Handling Multiple Windows in Citibank site

 



Find the code for handling multiple windows via windows handler the steps are given in detail

here on clicking on the first window a new window shall open and while you move to the new window does not mean moving driver to the 2nd window, but it will still point to parent window so how to move to child window to a parent window is defined here


@Test

public void test1() throws InterruptedException {

System.setProperty("Webdriver.chrome.driver", "chromedriver");

    WebDriver driver = new ChromeDriver();

   driver.get("https://www.online.citibank.co.in/");

   driver.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);

   System.out.println(driver.getTitle());

   //gives you ID of current window

   String pa = driver.getWindowHandle();

   System.out.println(pa);

   //to click on the login button which will open anew window

   driver.findElement(By.xpath("//*[@title='LOGIN NOW']/img")).click();;

   //allwin.size give you number of windows/popup open which is 2

   //set object does not store the  value on the basis of indexes

   Set<String> allwin = driver.getWindowHandles();

   int count = allwin.size();

   System.out.println(count);

   //in order to work on the new window you need to point your driver on the new window to do that iterate the windows

   //as windowhandles is a set object "For loop" wont work as set object does not store the  value on the basis of indexes instead we will use iterator

   //create iterator object

   Iterator <String> it =allwin.iterator();

   //it.next will give you parent window id value and Remember  your driver is still Ponting to the first window

   String parentwindow = it.next();

 System.out.println("parentwindow id"+" "+ parentwindow);

 //it.next if mentioned 2nd time it will point it to child window

 String childwindow =it.next();

 driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

 System.out.println("childwindow id"+" "+ childwindow);

 driver.switchTo().window(childwindow);

 System.out.println("title of childwindow"+" "+driver.getTitle()); 

//will quit the window where you driver is present

driver.quit

}

}


You can also check the execution of code here

Comments

Popular posts from this blog

Cucumber - Execution of test cases and reporting

Before going through this blog please checkout blog on   Cucumber Fundamentals Cucumber is testing tool which implements BDD(behaviour driven development).It offers a way to write tests that  anybody can understand, regardless of there technical knowledge. It users Gherkin (business readable language) which helps to  describe behaviour without going into details of implementation It's helpful for  business stakeholders who can't easily read code ( Why cucumber tool,  is  called  cucumber , I have no idea if you ask me I could have named it "Potato"(goes well with everything and easy to understand 😂) Well, According to its founder..... My wife suggested I call it  Cucumber  (for no particular reason), so that's how it got its  name . I also decided to give the Given-When-Then syntax a  name , to separate it from the  tool . That's why it's  called  Gherkin ( small variety of a cucumber that's been pickled. I...

Beginners tutorial -:working with JMeter in Mac and windows - Part-01

  Prequisite   you should have Java downloaded in your system with Home path set under environment variables.(as of today Java version 8 and higher are required fro jmeter ) for help check out this link Note Always run the jmeter on your secondary browser,  if you give the primary browser for proxy settings then your internet connection will be disrupted for the browser as well as system For ex if you have chrome and firefox and your primary or default browser is chrome then do all the proxy setting in firefox so it won't hamper the system Internet connection  if you have safari as your default browser in your mac os then set proxy in chrome/firefox  MAC Download jmeter from the link  here click on the hypelink under section Binaries  "Apache JMeter( 5.3 ). tgz" file  for Mac   Tar file will get downloaded Double click on the tar file to unzip  once you open the folder  got to bin and search for jmeter.sh file this is a executa...

Cucumber Datatable testing without using scenario outline and Issues

  Before going through this blog please visit blog The issue you might encounter while running cucumber project- 1.  you have created the cucumber all file in src/test/java and you are trying to  move it in another folder transition might not be smooth, It will give error one fix will led to other.(depends on the setup) 2. If on running a feature file and successfully creating a stepdef file, If application still says that  few steps are still needs to be implemented or all of them(not detecting creation of step definition) then there is a high chance you have mistakenly wrote some other annotation in stepdef when compares to you feature file eg:- feature file @And ( "^user close browser$" ) public   void  user_close_browser()  throws  Throwable { Stepdef:-             @Then ( "^user close browser$" ) public   void  user_close_browser()  throws  Throwable { driver .quit(); 3. Duplicate S...