title: How to accept alert in selenium which is coming up in a different window?
body: <p>Scenario: There are 2 windows open. When I am clicking a button on the 2nd window, a 3rd window is opening and the focus is automatically shifting to 3rd window. An alert is coming on the 3rd window to accept.</p>
  
  <p>Issue: I am not able to accept the alert as it's coming in a different window.</p>
  
  <p>Findings: I think it's the limitation of Selenium. If the alert is coming on the same window where the button is clicked, we have the DOM, so we are able to interact with the alert. But in this case the alert is in a different window, so the state of the browser is locked.</p>
  
  <p>Tried solution: Tried all the possible ways by using javascript, selenium action class etc, but it's not working.</p>
  
  <p>some of the tried methods are as below</p>
  
  <pre><code>//e.click();
                          /*Actions ac = new Actions(driver);
  
                          ac.sendKeys(Keys.ENTER).build().perform();*/
                          String onClickScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('click', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject){ arguments[0].fireEvent('onclick');}";
                          JavascriptExecutor jse = (JavascriptExecutor)driver;
                          jse.executeScript(onClickScript, e);
  
                      /*  Actions asd = new Actions(driver);
                          asd.clickAndHold(e).perform();
                          Thread.sleep(1000);
                          asd.release().perform();*/
  </code></pre>