SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
345 stars 195 forks source link

WebDriver randomly fails to accept javascript alert windows (timing problem) #3544

Closed lukeis closed 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 3544

> This is the exception stacktrace:

org.openqa.selenium.WebDriverException: a.document.getElementsByTagName("dialog")[0]
is undefined Command duration or timeout: 136 milliseconds Build info: version: '2.20.0',
revision: '16008', time: '2012-02-28 15:00:40' System info: os.name: 'Linux', os.arch:
'amd64', os.version: '3.0.0-1-amd64', java.version: '1.6.0_31' Driver info: driver.version:
RemoteWebDriver
org.openqa.selenium.WebDriverException: a.document.getElementsByTagName("dialog")[0]
is undefined
Command duration or timeout: 136 milliseconds
Build info: version: '2.20.0', revision: '16008', time: '2012-02-28 15:00:40'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.0.0-1-amd64', java.version:
'1.6.0_31'
Driver info: driver.version: RemoteWebDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:170)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:123)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:438)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:442)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteAlert.accept(RemoteWebDriver.java:714)
    at net.elitem.gui.model.base.WebDriverComponent.clickAndAcceptConfirmation(WebDriverComponent.java:158)

What steps will reproduce the problem?
        someElement.click(); // triggers a javascript confirmation dialog

        Alert alert = this.context.switchTo().alert();
        String actualConfirmationText = alert.getText();
        alert.accept();
        assertEquals(expectedConfirmationText, actualConfirmationText);

> What is the expected output? 

The confirmation window should be accepted.

> What do you see instead?

The test aborts with above exception.
Interestingly, getting the dialog's text works, but accepting it doesn't.

Selenium version: 2.20
OS: Linux amd64
Browser: Firefox
Browser version: 10

Reported by google_account@vesseltracker.com on 2012-03-13 09:28:43

lukeis commented 8 years ago
I want to add that it fails sometimes, not always. So it seems to be some kind of timing
problem. Adding a Thread.sleep() or fluentWait seems to help, but we are not completely
sure.

Reported by google_account@vesseltracker.com on 2012-03-13 09:30:42

lukeis commented 8 years ago
This issue was fixed in r16079 and should be fixed for 2.21

Reported by kristian.rosenvold on 2012-03-13 21:00:19

lukeis commented 8 years ago
I think this is actually a race-condition between our detection logic and the window
painting - can you update as to whether 2.21 fixes this, when it's released?

Reported by dawagner on 2012-03-17 23:34:06

lukeis commented 8 years ago
2.21 is available

Reported by barancev on 2012-05-10 21:05:15

lukeis commented 8 years ago
This is still happening for me with 2.21. For now, my workaround is to sleep a bit before
accepting the alert

Reported by infratl on 2012-05-11 17:32:58

lukeis commented 8 years ago
Still happening using 2.22.0.

Reported by david.w.andrews on 2012-06-07 19:07:34

lukeis commented 8 years ago
I am also seeing this issue with 2.23.1.  In the following code:

} else if (action.equalsIgnoreCase("continue")) {
    driver.switchTo().alert().accept();
        return "pass";

The 'continue' text is successfully detected, but the accept() method is failing with:

Caused by: org.openqa.selenium.WebDriverException: a.document.getElementsByTagName("dialog")[0]
is undefined

So, it appears WebDriver has detected the correct window and can read text.

- Chris

Reported by ckretler@umich.edu on 2012-06-18 21:23:41

lukeis commented 8 years ago
I should mention that this is not an issue on Ubuntu 10.04.  We only see this on Windows
7 and it is regular, but not constant.  It is more likely to occur when running many
tests before this one.  When I run this test in isolation on Windows 7, it typically
runs successfully.

Reported by ckretler@umich.edu on 2012-06-18 21:27:13

lukeis commented 8 years ago
I don't think this is a Windows issue only. I am seeing this error on unix (fc13) using
selenium 2.24.1 as well.

Reported by rahulpoonekar on 2012-07-10 22:43:38

lukeis commented 8 years ago
Also getting this in 2.24.1.
This throws the same exception (sometimes):

Alert alert = null;
Wait<WebDriver> wait = new WebDriverWait(driver, 10, 50);
try {
   alert = wait.until(ExpectedConditions.alertIsPresent());
} catch (TimeoutException ignored) {
}
if (alert != null) {
   alert.accept(); // this line throws the exception
}

Reported by dzhang@presagia.com on 2012-07-20 13:43:16

lukeis commented 8 years ago
I am also seeing this issue on windows xp and chrome using latest webdriver 2.24.1

Reported by glblrelayprimary on 2012-07-25 23:11:01

lukeis commented 8 years ago
Am also seeing this issues when using FirefoxDriver.

Reported by arran.huxtable on 2012-07-26 14:37:31

lukeis commented 8 years ago
We also get random failures on Windows 7 and Chrome using Selenium 2.25. We tried pretty
much everything that was suggested on forums and nothing seems to fix it.

Any idea on what is going on?

Reported by simon.godard on 2012-09-11 12:19:41

lukeis commented 8 years ago
Same behaviour here (W7, FF3.6, WebDriver 2.25)

Reported by t34@blaupost.de on 2012-09-12 17:10:12

lukeis commented 8 years ago
Same behaviour here (W7, FF16, WebDriver 2.29)

Reported by gonella on 2013-02-21 13:10:19

lukeis commented 8 years ago
We also get random failures on Windows 2008 and FireFox using Selenium 2.25.

Reported by cuipengfei2008 on 2013-03-06 09:13:23

lukeis commented 8 years ago
@16, you've updated Selenium and verified it also happens on v2.3.1, *right*? What version
of Firefox?

Reported by arran.huxtable on 2013-03-06 09:31:46

lukeis commented 8 years ago
@17 , no, I have not tried 2.31, I am using 2.25. I'll try 2.31 later.
For my particular case, I don't think the version of FireFox matter, because my local
machine(win7) and my CI build machine(win2008) are using the same version of FireFox.
And it only happens on Windows 2008.

Reported by cuipengfei2008 on 2013-03-06 12:57:49

lukeis commented 8 years ago
Windows 2008 and FireFox 17 using Selenium 2.31

Getting similar error: a.document.getElementsByTagName(...)[0] is undefined Command.

Reported by cuipengfei2008 on 2013-03-11 08:12:48

lukeis commented 8 years ago
We see this with Selenium 2.31 on Ubuntu with Firefox 14

Reported by kieranshaw on 2013-05-16 13:35:48

lukeis commented 8 years ago
Windows xp and Firefox 17 with Selenium2.28

It happens for few times when accept confirmation pop up: a.document.getElementsByTagName(...)[0]
is undefined

Reported by chenxu1985 on 2013-05-28 09:33:15

lukeis commented 8 years ago
Also observed in 2.33

Reported by damith on 2013-06-15 15:55:26

lukeis commented 8 years ago
Seeing this on the latest version of Firefox and Windows Server 2008, selenium server
2.33.

Reported by popa.bogdanp on 2013-06-21 13:10:13

lukeis commented 8 years ago
Same problem on Windows Server 2012 and selenium 2.33

Reported by k.s.seroka on 2013-06-29 09:50:44

lukeis commented 8 years ago
Same problem with Windows server 2008 and selenium 2.33

Reported by mak83826 on 2013-07-18 04:41:10

lukeis commented 8 years ago
The same error occurs randomly on invoking Alert.dismiss().

Code :-

WebDriverWait wait = new WebDriverWait(webDriver, timeout);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());

alert.dismiss();

Reported by AshwinPrabhuB on 2013-08-12 10:46:11

lukeis commented 8 years ago
The same problem on Windows 7, Webdriver 2.35.0.

Reported by creathorx on 2013-08-29 12:04:39

lukeis commented 8 years ago
Same problem Windows 7, Webdriver 2.35.0

As a workaround I wrapped accept call in a try catch and looped until it was successful:

    public void clickOkOnAlertDialog(String dialogText) {

        Sync sync = Sync.start(20);
        while (sync.continueWaiting()) {
            wait = new WebDriverWait(driver, pageTimeoutInSeconds);
            wait.until(ExpectedConditions.alertIsPresent());
            Alert statusConfirm = driver.switchTo().alert();
            junit.framework.Assert.assertEquals(dialogText, statusConfirm.getText());
            try {
                statusConfirm.accept();
                return;
            } catch (WebDriverException e) {
                sync.sleep(250);
            }
        }
        throw new TimeoutException("Unable to locate and dismiss alert dialog: " +
dialogText);
    }

Reported by guy.dipietro on 2013-09-05 15:18:53

lukeis commented 8 years ago
Also the same problem here on Windows Server 2008 Firefox 17.0.9 with Selenium 2.37.0.

Reported by OsswaldM94 on 2013-12-18 10:50:30

lukeis commented 8 years ago
I also just randomly saw this error on 64 bit Win 7, Selenium 2.39.0, FF 26.0.

Specifically, I got the following exception when trying to accept an alert:
  ...
  File "C:\Python275\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\common\alert.py",
line 78, in accept
    self.driver.execute(Command.ACCEPT_ALERT)
  File "C:\Python275\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\remote\webdriver.py",
line 164, in execute
    self.error_handler.check_response(response)
  File "C:\Python275\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py",
line 164, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: u'a.document.getElementsByTagName(...)[0] is undefined'
; Stacktrace: 
    at fxdriver.modals.findButton_ (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/driver_component.js:8412)
    at fxdriver.modals.acceptAlert (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/driver_component.js:8383)
    at FirefoxDriver.prototype.acceptAlert/< (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/driver_component.js:9085)
    at fxdriver.modals.isModalPresent/< (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/driver_component.js:8376)
    at fxdriver.Timer.prototype.runWhenTrue/g (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/driver_component.js:402)
    at fxdriver.Timer.prototype.runWhenTrue (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/driver_component.js:404)
    at fxdriver.modals.isModalPresent (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/driver_component.js:8377)
    at FirefoxDriver.prototype.acceptAlert (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/driver_component.js:9087)
    at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/command_processor.js:10831)
    at DelayedCommand.prototype.executeInternal_ (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/command_processor.js:10836)
    at DelayedCommand.prototype.execute/< (file:///c:/users/bfs/appdata/local/temp/tmpyzdwy_/extensions/fxdriver@googlecode.com/components/command_processor.js:10778)

Reported by michael.herrmann@open-closure.com on 2014-01-24 18:11:28

lukeis commented 8 years ago
If you run selenium-webdriver app in console, make sure that the browser window that
appears after the app starts does NOT have focus. You can for example click on your
console window as soon as the browser window appears. This should do it:)

If you do not run in console, still, make sure browser window is out of focus.

Reported by watherby on 2014-02-10 13:13:30

lukeis commented 8 years ago
It core problem and it is present in current last version 2.42.2 of selenium
It happens mostly on slow machines and on pages with heavy JavaScript
The user side solution - wait for some time for element like here http://code.google.com/p/selenium/issues/detail?id=3544#c29
But would be nice to fix this problem by adding timeout attribute in the core

Reported by 66ton99 on 2014-06-18 11:36:34

lukeis commented 8 years ago
Can some one post a solution code .

I have the same issue JavaScript Error: "e is null , when I run my test now, which
were running fine yesterday.

I have 3 tests in the same class specified by @test. If I comment out any one test,
the other 2 runs fine.

I am not sure how to solve this issue. Can someone help me.

Reported by redroseclt on 2014-07-03 14:35:01

lukeis commented 8 years ago
can anybody found a solution for this,any help appreciated

Reported by ngupta@tk20.com on 2014-07-11 13:42:28

lukeis commented 8 years ago
Would love to see this finally fixed too!

Reported by Timofey.Vasenin on 2014-07-22 14:58:46

lukeis commented 8 years ago
Is there a reproduction scenario and page to debug the issue?

Reported by barancev on 2014-07-23 08:25:04

lukeis commented 8 years ago
Seeing this problem intermittently in Firefox on slower Windows Server 2008 R2 machine
against an Angular JS application, but not on faster Mac and Windows systems. In previous
versions of Selenium, we used the workaround of catching WebDriverException on alert.accept()
and .dismiss() and retrying until a timeout is reached. On 2.42.2 with FirefoxDriver
Java driver and Firefox 31.0, the .accept() and .dismiss() just hang. I have to manually
close the browser window which results in it finally coming back with an UnreachableBrowserException.
I will also say that it always fails in a particular part of the test where it is testing
various error conditions, each resulting in an alert(), between entering data in a
form and clicking a submit button. It almost always hangs on the 5th alert in my case.

Reported by joshden on 2014-08-11 15:57:24

lukeis commented 8 years ago
I get this:

AssertionError: WebDriverException: Message: u'[JavaScript Error: "e is null" {file:
"file:///tmp/tmp8LbDqE/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command_processor.js"
line: 7716}]\'[JavaScript Error: "e is null" {file: "file:///tmp/tmp8LbDqE/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command_processor.js"
line: 7716}]\' when calling method: [nsICommandProcessor::execute]'

always - I use robot framework. Test are executed on Ubuntu and Firefox.

Reported by marcin.staniszczak on 2014-08-27 00:05:23

lukeis commented 8 years ago
Getting this failure on Windows 8.1 and Firefox ESR 31.0:

Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: [JavaScript
Error: "a.document.getElementsByTagName(...)[0].getButton is not a function" {file:
"file:///C:/Users/dwray/AppData/Local/Temp/anonymous6976981321126831255webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js"
line: 8120}]'[JavaScript Error: "a.document.getElementsByTagName(...)[0].getButton
is not a function" {file: "file:///C:/Users/dwray/AppData/Local/Temp/anonymous6976981321126831255webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js"
line: 8120}]' when calling method: [nsICommandProcessor::execute]
Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc',
time: '2014-06-03 10:52:47'
System info: host: 'T530-1273-DW', ip: '192.168.241.90', os.name: 'Windows 8', os.arch:
'amd64', os.version: '6.2', java.version: '1.7.0_25'

Would love to hear of a work-around.

Reported by dwrays on 2014-09-04 11:17:43

lukeis commented 8 years ago
Does anyone have a succesfull workaroud to this problem?

I'm facing the same Exception using Windows 2008 server and Firefox, and the page I'm
browsing don't have Alerts.

Thanks in advance.

Reported by medeiros.ary on 2014-09-26 01:05:48

lukeis commented 8 years ago
Also as I. On my website also does not have any dialogs, alerts and so on (# 39). And
it completely stopped my work with the tests:/ 

Reported by marcin.staniszczak on 2014-09-26 09:35:09

lukeis commented 8 years ago
*** Versions

Selenium version: 2.43.0
Browser: Firefox 31.2.0
OS: Debian testing up to date as of 2014/10/17

** What steps will reproduce the problem?

1. Download the `issue.py` file. It reproduces the problem 100% of the time here.

2. Edit it so that the Firefox binary used is 31.2.0.

3. Run it:

    python ./issue.py

** What is the expected output?

No exceptions.

** What do you see instead?

Traceback (most recent call last):
  File "issue.py", line 14, in <module>
    driver.delete_all_cookies()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
line 587, in delete_all_cookies
    self.execute(Command.DELETE_ALL_COOKIES)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
line 173, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py",
line 166, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u'[JavaScript Error: "a.document.getElementsByTagName(...)[0].getButton
is not a function" {file: "file:///tmp/tmpgauKk4/extensions/fxdriver@googlecode.com/components/command-processor.js"
line: 8877}]\'[JavaScript Error: "a.document.getElementsByTagName(...)[0].getButton
is not a function" {file: "file:///tmp/tmpgauKk4/extensions/fxdriver@googlecode.com/components/command-processor.js"
line: 8877}]\' when calling method: [nsICommandProcessor::execute]'

** Observations

Only able to reproduce it with FF 31.2.0.

The timing is very sensitive. Without `setTimeout` Selenium detects the alert properly.
It does not take much of an increase beyond 1 to cause the test to avoid the exception.

I believe this error is related to: https://code.google.com/p/selenium/issues/detail?id=7977

Reported by avaktavyam on 2014-10-17 15:50:38


lukeis commented 8 years ago
This issue was closed by revision 38e8a90463c4.

Reported by barancev on 2014-11-05 22:09:05

lukeis commented 8 years ago
alert.accept(); is not working in the current version

Reported by vgollakoti on 2014-11-13 20:58:14

lukeis commented 8 years ago
I'm facing same issue , let's hope it gets fixed in next version of Selenium WebDriver.

Reported by piyush.patel@clariontechnologies.co.in on 2014-11-21 06:13:05

lukeis commented 8 years ago
Any updates on this issue please...

Reported by vgollakoti on 2015-01-27 16:09:20

lukeis commented 8 years ago
I'm also looking for an update on this ideally.  I am running into this issue.

Reported by CTruncer on 2015-03-17 20:24:34

lukeis commented 8 years ago
i solved this issue by adding time.sleep for few seconds. and this also helps when Selenium
randomly does not find some element on page.

Reported by ma.podoplelov on 2015-03-18 07:44:44

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 18:15:03