selenium-google-code-issue-archive icon indicating copy to clipboard operation
selenium-google-code-issue-archive copied to clipboard

Exception when trying to access alert in a different window (Firefox/Chrome)

Open lukeis opened this issue 9 years ago • 3 comments

Originally reported on Google Code with ID 7807

What steps will reproduce the problem? (Firefox)

1. Open a window that immediately opens and alert
2. Make a call to getWindowHandles(), and switch to the previous window
3. Switch to the window that opened the alert
4. Attempt to accept the alert

driver.getWindowHandles();
driver.switchTo().window("window1");        
driver.switchTo().window("window2"); // the window with the alert
driver.switchTo().alert().accept();


What is the expected output? What do you see instead?

In the case above, we expect the driver to switch to window1, then to window2, and
finally to accept the alert.

The above will fail with an org.openqa.selenium.NoAlertPresentException. However, if
you remove the call to getWindowHandles() or the call to driver.switchTo().window("window1"),
the alert will be successfully closed.

In the case of Chrome, we are unable to close the alert dialogue even when those two
lines are removed. 

Selenium version: 2.42.2
OS: Windows 7 64bit
Browser: Firefox 31.0 /Chrome 36.0.1985.143



Please provide any additional information below.

WebDriver driver = new FirefoxDriver();
driver.get("index.html");

String path = "/descendant::div[normalize-space(.)=\"open a window\"]";
WebElement element = driver.findElement(By.xpath(path));
Actions builder = new Actions(driver);
builder.click(element).perform();

driver.getWindowHandles();
driver.switchTo().window("window1");
driver.switchTo().window("window2");
driver.switchTo().alert().accept();

Reported by para.selenium.bugs on 2014-08-29 23:54:32


- _Attachment: [index.html](https://storage.googleapis.com/google-code-attachments/selenium/issue-7807/comment-0/index.html)_ - _Attachment: [opened.html](https://storage.googleapis.com/google-code-attachments/selenium/issue-7807/comment-0/opened.html)_

lukeis avatar Mar 04 '16 08:03 lukeis

Reported by barancev on 2014-08-30 16:18:53

  • Labels added: Browser-Firefox, Browser-Chrome

lukeis avatar Mar 04 '16 08:03 lukeis

The attached sample opens a new window, but it does not immediately open an alert in
the new window.

Nevertheless, I've fixed the sample and reproduced the issue.

Reported by barancev on 2014-09-24 06:20:34

  • Status changed: Accepted
  • Labels removed: Status-Untriaged

lukeis avatar Mar 04 '16 08:03 lukeis

Reported by luke.semerau on 2015-09-17 17:47:05

  • Labels added: Restrict-AddIssueComment-Commit

lukeis avatar Mar 04 '16 08:03 lukeis