Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

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

Open
lukeis opened this issue Mar 4, 2016 · 3 comments
Open

Comments

@lukeis
Copy link
Member

lukeis commented Mar 4, 2016

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
Copy link
Member Author

lukeis commented Mar 4, 2016

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

  • Labels added: Browser-Firefox, Browser-Chrome

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

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
Copy link
Member Author

lukeis commented Mar 4, 2016

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

  • Labels added: Restrict-AddIssueComment-Commit

@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant