New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium does not wait after calling WebElement.submit() #4570

Closed
mgruner opened this Issue Aug 24, 2017 · 27 comments

Comments

Projects
None yet
6 participants
@mgruner

mgruner commented Aug 24, 2017

Meta -

OS: OS X 10.11.6 (15G1611)
Selenium Version: 3.4.0
Browser: Firefox 55.0.2

Originally opened at mozilla/geckodriver#878, but then I was referred to here.

Expected Behavior -

With Firefox 47 (without marionette), calling submit() on a WebElement caused Selenium to wait until the page load starts (just as it also works in current Chrome).

Actual Behavior -

This is not the case with current Firefox that uses WebDriver. Is that intended behaviour? Our test suite relies on that implicit wait currently.

Steps to reproduce -

If a submit() is triggered on a form, the following test code runs in the context of the old page.

Possible issue -

Information by @andreastt in the geckodriver issue:

Do note that there is no submit command in the WebDriver specification, so my suspicion is that the shim Selenium uses to map it to a valid WebDriver primitive is wrong. If Selenium were to map WebElement#submit() to Element Click, which we have confirmed waits for the document to finish loading, it should work just fine provided you are using the normal page loading strategy.

Any help will be most appreciated. Sorry, I'm not familiar with the technical details of Selenium's internals.

@barancev

This comment has been minimized.

Show comment
Hide comment
@barancev

barancev Aug 24, 2017

Member

For issues please provide a concise reproducible test case and describe what results you are seeing and what results you expect.

See CONTRIBUTING.md

Member

barancev commented Aug 24, 2017

For issues please provide a concise reproducible test case and describe what results you are seeing and what results you expect.

See CONTRIBUTING.md

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Aug 28, 2017

@barancev of course.

You need the CPAN module Selenium::Remote::Driver, installable via cpanm Selenium::Remote::Driver, for example.

Here's a small Perl test script:

use strict;
use warnings;

use Selenium::Remote::Driver;

my $Selenium = Selenium::Remote::Driver->new(
    remote_server_addr  => 'localhost',
    port                => '4444',
    browser_name        => 'firefox',
    platform            => 'ANY',
    extra_capabilities => {
        marionette     => \0,   # Required to run FF 47 or older on Selenium 3+.
    },
);

$Selenium->get('https://www.google.com');
my $Element = $Selenium->find_element('form input.gsfi', 'css');
$Element->send_keys('Selenium');
$Element->submit();

if ($Selenium->get_page_source() !~ 'seleniumhq\.org') {
    die "Error: Selenium home page not found.";
}
else {
    print "Ok: Selenium home page found.\n"
}

If you run this with Firefox 47 (and the marionette => 0 line enabled), it works correctly. After the submit, Selenium waits, and get_page_source retrieves the new page with the Selenium home page in the results.

Tested with Firefox 55.0.3 (and the marionette => 0line disabled), Selenium does not wait. After the submit, get_page_source delivers the original page with the search form and no results.

mgruner commented Aug 28, 2017

@barancev of course.

You need the CPAN module Selenium::Remote::Driver, installable via cpanm Selenium::Remote::Driver, for example.

Here's a small Perl test script:

use strict;
use warnings;

use Selenium::Remote::Driver;

my $Selenium = Selenium::Remote::Driver->new(
    remote_server_addr  => 'localhost',
    port                => '4444',
    browser_name        => 'firefox',
    platform            => 'ANY',
    extra_capabilities => {
        marionette     => \0,   # Required to run FF 47 or older on Selenium 3+.
    },
);

$Selenium->get('https://www.google.com');
my $Element = $Selenium->find_element('form input.gsfi', 'css');
$Element->send_keys('Selenium');
$Element->submit();

if ($Selenium->get_page_source() !~ 'seleniumhq\.org') {
    die "Error: Selenium home page not found.";
}
else {
    print "Ok: Selenium home page found.\n"
}

If you run this with Firefox 47 (and the marionette => 0 line enabled), it works correctly. After the submit, Selenium waits, and get_page_source retrieves the new page with the Selenium home page in the results.

Tested with Firefox 55.0.3 (and the marionette => 0line disabled), Selenium does not wait. After the submit, get_page_source delivers the original page with the search form and no results.

@barancev

This comment has been minimized.

Show comment
Hide comment
@barancev

barancev Aug 28, 2017

Member

Last Firefox version supported by legacy Firefox driver is 52 ESR.
To run tests in Firefox 55 you have to use geckodriver.

Member

barancev commented Aug 28, 2017

Last Firefox version supported by legacy Firefox driver is 52 ESR.
To run tests in Firefox 55 you have to use geckodriver.

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Aug 28, 2017

@barancev Please don't close this! Of course I used geckodriver. Removing the line marionette => \0 from the configuration causes Selenium to use the installed geckodriver to talk to Firefox. And that seems to cause the issue of the wrong waiting. I even originally submitted the issue with the geckodriver project, but they told me to report it here instead, as they believe it could be an issue with the shim that Selenium uses to implement submitElement with WebDriver, that does not have such a function.

mgruner commented Aug 28, 2017

@barancev Please don't close this! Of course I used geckodriver. Removing the line marionette => \0 from the configuration causes Selenium to use the installed geckodriver to talk to Firefox. And that seems to cause the issue of the wrong waiting. I even originally submitted the issue with the geckodriver project, but they told me to report it here instead, as they believe it could be an issue with the shim that Selenium uses to implement submitElement with WebDriver, that does not have such a function.

@barancev

This comment has been minimized.

Show comment
Hide comment
@barancev

barancev Aug 28, 2017

Member

Sorry, I saw marionette => \0 in your code and decided you're trying to drive Firefox 55 with legacy driver.

But I have to say that CPAN module Selenium::Remote::Driver is not a software developed by Selenium team, so you have to report the issue to this Perl library bug tracker.

Member

barancev commented Aug 28, 2017

Sorry, I saw marionette => \0 in your code and decided you're trying to drive Firefox 55 with legacy driver.

But I have to say that CPAN module Selenium::Remote::Driver is not a software developed by Selenium team, so you have to report the issue to this Perl library bug tracker.

@barancev

This comment has been minimized.

Show comment
Hide comment
@barancev

barancev Aug 28, 2017

Member

One more note: I tried to run your code sample with Selenium::Remote::Driver version 1.0 and Selenium server 3.5.2 and it fails on send_keys operation because the client library does not send element identifier.

Client side log:

Use of uninitialized value in substitution iterator at C:/Perl64/site/lib/Seleni
um/Remote/Commands.pm line 437.
Error while executing command: sendKeysToElement: The requested resource could n
ot be found, or a request was received using an HTTP method that is not supporte
d by the mapped resource.: POST /session/dfb48504-8f12-4ae3-a31f-da8c2984e84d/el
ement//value
Build info: version: '3.5.2', revision: 'unknown', time: '2017-08-24T16:43:06.09
4Z'
System info: host: 'ALEXEI-PC', ip: '192.168.56.1', os.name: 'Windows 7', os.arc
h: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: driver.version: unknown at C:/Perl64/site/lib/Selenium/Remote/Drive
r.pm line 313.
 at C:/Perl64/site/lib/Selenium/Remote/Driver.pm line 313.

Server log:

14:43:12.687 INFO - /session: Executing POST on /session (handler: BeginSession)

14:43:12.688 INFO - Capabilities are: Capabilities {acceptSslCerts=true, browser
Name=firefox, javascriptEnabled=true, platformName=ANY, version=, platform=ANY,
}
14:43:12.688 INFO - Capabilities {acceptSslCerts=true, browserName=firefox, java
scriptEnabled=true, platformName=ANY, version=, platform=ANY, } matched class or
g.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.se
lenium.firefox.GeckoDriverService)
14:43:12.689 INFO - Capabilities {acceptSslCerts=true, browserName=firefox, java
scriptEnabled=true, platformName=ANY, version=, platform=ANY, } matched class or
g.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.se
lenium.chrome.ChromeDriverService)
1503920592712   geckodriver     INFO    geckodriver 0.18.0
1503920592719   geckodriver     INFO    Listening on 127.0.0.1:20430
1503920593222   geckodriver::marionette INFO    Starting browser C:\Program File
s\Nightly\firefox.exe with args ["-marionette"]
1503920593664   addons.xpi      WARN    Error parsing extensions state: [Excepti
on... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [am
IAddonManagerStartup.readStartupData]"  nsresult: "0x80520012 (NS_ERROR_FILE_NOT
_FOUND)"  location: "JS frame :: resource://gre/modules/addons/XPIProvider.jsm :
: loadExtensionState :: line 1521"  data: no] Stack trace: loadExtensionState()@
resource://gre/modules/addons/XPIProvider.jsm:1521 < getInstallState()@resource:
//gre/modules/addons/XPIProvider.jsm:1556 < checkForChanges()@resource://gre/mod
ules/addons/XPIProvider.jsm:3091 < startup()@resource://gre/modules/addons/XPIPr
ovider.jsm:2158 < callProvider()@resource://gre/modules/AddonManager.jsm:263 < _
startProvider()@resource://gre/modules/AddonManager.jsm:731 < startup()@resource
://gre/modules/AddonManager.jsm:898 < startup()@resource://gre/modules/AddonMana
ger.jsm:3082 < observe()@jar:file:///C:/Program%20Files/Nightly/omni.ja!/compone
nts/addonManager.js:65
1503920594015   Marionette      INFO    Enabled via --marionette
Unable to read VR Path Registry from C:\Users\alexei\AppData\Local\openvr\openvr
paths.vrpath
[Parent 8804] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src
/chrome/common/ipc_channel_win.cc, line 346
Unable to read VR Path Registry from C:\Users\alexei\AppData\Local\openvr\openvr
paths.vrpath
[Child 17904] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src
/chrome/common/ipc_channel_win.cc, line 346
[Child 17904] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src
/chrome/common/ipc_channel_win.cc, line 346
1503920595641   Marionette      INFO    Listening on port 65223
1503920595983   Marionette      DEBUG   Register listener.js for window 42949672
97
14:43:16.003 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSes
sion@1251f217
14:43:16.004 INFO - Handler thread for session bda92b59-5509-4186-b151-0d13d877c
745 (firefox): Executing POST on /session/bda92b59-5509-4186-b151-0d13d877c745/u
rl (handler: ServicedSession)
1503920596012   Marionette      DEBUG   Received DOM event "beforeunload" for "a
bout:blank"
1503920596313   Marionette      DEBUG   Received DOM event "pagehide" for "about
:blank"
1503920596314   Marionette      DEBUG   Received DOM event "unload" for "about:b
lank"
1503920596385   Marionette      DEBUG   Received DOM event "DOMContentLoaded" fo
r "https://www.google.ru/?gfe_rd=cr&ei=0wGkWfOlItHCtAGmmKbgAw"
1503920596581   Marionette      DEBUG   Received DOM event "pageshow" for "https
://www.google.ru/?gfe_rd=cr&ei=0wGkWfOlItHCtAGmmKbgAw"
14:43:16.592 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSes
sion@1251f217
14:43:16.592 INFO - Handler thread for session bda92b59-5509-4186-b151-0d13d877c
745 (firefox): Executing POST on /session/bda92b59-5509-4186-b151-0d13d877c745/e
lement (handler: ServicedSession)
14:43:16.727 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSes
sion@1251f217
14:43:16.728 INFO - Handler thread for session bda92b59-5509-4186-b151-0d13d877c
745 (firefox): Executing POST on /session/bda92b59-5509-4186-b151-0d13d877c745/e
lement//value (handler: ServicedSession)
14:43:16.737 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSes
sion@1251f217
Member

barancev commented Aug 28, 2017

One more note: I tried to run your code sample with Selenium::Remote::Driver version 1.0 and Selenium server 3.5.2 and it fails on send_keys operation because the client library does not send element identifier.

Client side log:

Use of uninitialized value in substitution iterator at C:/Perl64/site/lib/Seleni
um/Remote/Commands.pm line 437.
Error while executing command: sendKeysToElement: The requested resource could n
ot be found, or a request was received using an HTTP method that is not supporte
d by the mapped resource.: POST /session/dfb48504-8f12-4ae3-a31f-da8c2984e84d/el
ement//value
Build info: version: '3.5.2', revision: 'unknown', time: '2017-08-24T16:43:06.09
4Z'
System info: host: 'ALEXEI-PC', ip: '192.168.56.1', os.name: 'Windows 7', os.arc
h: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: driver.version: unknown at C:/Perl64/site/lib/Selenium/Remote/Drive
r.pm line 313.
 at C:/Perl64/site/lib/Selenium/Remote/Driver.pm line 313.

Server log:

14:43:12.687 INFO - /session: Executing POST on /session (handler: BeginSession)

14:43:12.688 INFO - Capabilities are: Capabilities {acceptSslCerts=true, browser
Name=firefox, javascriptEnabled=true, platformName=ANY, version=, platform=ANY,
}
14:43:12.688 INFO - Capabilities {acceptSslCerts=true, browserName=firefox, java
scriptEnabled=true, platformName=ANY, version=, platform=ANY, } matched class or
g.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.se
lenium.firefox.GeckoDriverService)
14:43:12.689 INFO - Capabilities {acceptSslCerts=true, browserName=firefox, java
scriptEnabled=true, platformName=ANY, version=, platform=ANY, } matched class or
g.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.se
lenium.chrome.ChromeDriverService)
1503920592712   geckodriver     INFO    geckodriver 0.18.0
1503920592719   geckodriver     INFO    Listening on 127.0.0.1:20430
1503920593222   geckodriver::marionette INFO    Starting browser C:\Program File
s\Nightly\firefox.exe with args ["-marionette"]
1503920593664   addons.xpi      WARN    Error parsing extensions state: [Excepti
on... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [am
IAddonManagerStartup.readStartupData]"  nsresult: "0x80520012 (NS_ERROR_FILE_NOT
_FOUND)"  location: "JS frame :: resource://gre/modules/addons/XPIProvider.jsm :
: loadExtensionState :: line 1521"  data: no] Stack trace: loadExtensionState()@
resource://gre/modules/addons/XPIProvider.jsm:1521 < getInstallState()@resource:
//gre/modules/addons/XPIProvider.jsm:1556 < checkForChanges()@resource://gre/mod
ules/addons/XPIProvider.jsm:3091 < startup()@resource://gre/modules/addons/XPIPr
ovider.jsm:2158 < callProvider()@resource://gre/modules/AddonManager.jsm:263 < _
startProvider()@resource://gre/modules/AddonManager.jsm:731 < startup()@resource
://gre/modules/AddonManager.jsm:898 < startup()@resource://gre/modules/AddonMana
ger.jsm:3082 < observe()@jar:file:///C:/Program%20Files/Nightly/omni.ja!/compone
nts/addonManager.js:65
1503920594015   Marionette      INFO    Enabled via --marionette
Unable to read VR Path Registry from C:\Users\alexei\AppData\Local\openvr\openvr
paths.vrpath
[Parent 8804] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src
/chrome/common/ipc_channel_win.cc, line 346
Unable to read VR Path Registry from C:\Users\alexei\AppData\Local\openvr\openvr
paths.vrpath
[Child 17904] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src
/chrome/common/ipc_channel_win.cc, line 346
[Child 17904] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src
/chrome/common/ipc_channel_win.cc, line 346
1503920595641   Marionette      INFO    Listening on port 65223
1503920595983   Marionette      DEBUG   Register listener.js for window 42949672
97
14:43:16.003 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSes
sion@1251f217
14:43:16.004 INFO - Handler thread for session bda92b59-5509-4186-b151-0d13d877c
745 (firefox): Executing POST on /session/bda92b59-5509-4186-b151-0d13d877c745/u
rl (handler: ServicedSession)
1503920596012   Marionette      DEBUG   Received DOM event "beforeunload" for "a
bout:blank"
1503920596313   Marionette      DEBUG   Received DOM event "pagehide" for "about
:blank"
1503920596314   Marionette      DEBUG   Received DOM event "unload" for "about:b
lank"
1503920596385   Marionette      DEBUG   Received DOM event "DOMContentLoaded" fo
r "https://www.google.ru/?gfe_rd=cr&ei=0wGkWfOlItHCtAGmmKbgAw"
1503920596581   Marionette      DEBUG   Received DOM event "pageshow" for "https
://www.google.ru/?gfe_rd=cr&ei=0wGkWfOlItHCtAGmmKbgAw"
14:43:16.592 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSes
sion@1251f217
14:43:16.592 INFO - Handler thread for session bda92b59-5509-4186-b151-0d13d877c
745 (firefox): Executing POST on /session/bda92b59-5509-4186-b151-0d13d877c745/e
lement (handler: ServicedSession)
14:43:16.727 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSes
sion@1251f217
14:43:16.728 INFO - Handler thread for session bda92b59-5509-4186-b151-0d13d877c
745 (firefox): Executing POST on /session/bda92b59-5509-4186-b151-0d13d877c745/e
lement//value (handler: ServicedSession)
14:43:16.737 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSes
sion@1251f217
@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Aug 28, 2017

@barancev what Selenium::Remote::Driver does is just to send the submitElement command to Selenium, no matter which browser (version) is being used. Therefore I don't believe that the problem exists in the Perl bindings. Do you think you could try this very simple snipped in another language that is supported by Selenium, or am I required to provide a transpilation? Which languages would be acceptable?

mgruner commented Aug 28, 2017

@barancev what Selenium::Remote::Driver does is just to send the submitElement command to Selenium, no matter which browser (version) is being used. Therefore I don't believe that the problem exists in the Perl bindings. Do you think you could try this very simple snipped in another language that is supported by Selenium, or am I required to provide a transpilation? Which languages would be acceptable?

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Aug 28, 2017

@barancev, please use a recent version of Selenium::Remote::Driver, 1.20 is current.

mgruner commented Aug 28, 2017

@barancev, please use a recent version of Selenium::Remote::Driver, 1.20 is current.

@barancev

This comment has been minimized.

Show comment
Hide comment
@barancev

barancev Aug 28, 2017

Member

If Perl binding just sends submitElement commant -- it's problem of the binding. Because W3C WebDriver standard does not include this command: https://w3c.github.io/webdriver/webdriver-spec.html

That's exactly what @andreastt pointed at. This command should be either emulated in the client library, or removed at all. W3C conformant drivers can't handle this command.

Member

barancev commented Aug 28, 2017

If Perl binding just sends submitElement commant -- it's problem of the binding. Because W3C WebDriver standard does not include this command: https://w3c.github.io/webdriver/webdriver-spec.html

That's exactly what @andreastt pointed at. This command should be either emulated in the client library, or removed at all. W3C conformant drivers can't handle this command.

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Aug 28, 2017

@barancev just to make sure that I understand this correctly. Selenium does receive the command, and also causes a submit on the page. Just that it does not wait correctly, as it did before using the WebDriver interface (with old Firefox and also with current Chrome). So it seems that the "emulation" you mentioned does exist in Selenium, right? Shouldn't it be fixed there then?

mgruner commented Aug 28, 2017

@barancev just to make sure that I understand this correctly. Selenium does receive the command, and also causes a submit on the page. Just that it does not wait correctly, as it did before using the WebDriver interface (with old Firefox and also with current Chrome). So it seems that the "emulation" you mentioned does exist in Selenium, right? Shouldn't it be fixed there then?

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Aug 28, 2017

@andreastt explicitly mentioned it as a shim in Selenium that should be fixed.

mgruner commented Aug 28, 2017

@andreastt explicitly mentioned it as a shim in Selenium that should be fixed.

@barancev

This comment has been minimized.

Show comment
Hide comment
@barancev

barancev Aug 28, 2017

Member

OK, I've figured out, that Selenium server actually provides such a shim for non-W3C-compliant client libraries. Sorry to mislead you.

Now back to the original issue. Should Selenium wait for the next page to load after submit operation or not? @shs96c ?

Member

barancev commented Aug 28, 2017

OK, I've figured out, that Selenium server actually provides such a shim for non-W3C-compliant client libraries. Sorry to mislead you.

Now back to the original issue. Should Selenium wait for the next page to load after submit operation or not? @shs96c ?

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Aug 28, 2017

@barancev NP. Thanks for responding so fast!

mgruner commented Aug 28, 2017

@barancev NP. Thanks for responding so fast!

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Sep 1, 2017

Selenium 3.5.3 has the same behaviour.

mgruner commented Sep 1, 2017

Selenium 3.5.3 has the same behaviour.

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Sep 6, 2017

@barancev may I kindly ask for the status of this? How can we proceed?

mgruner commented Sep 6, 2017

@barancev may I kindly ask for the status of this? How can we proceed?

@barancev

This comment has been minimized.

Show comment
Hide comment
@barancev

barancev Sep 6, 2017

Member

No estimations. We don't consider this to be a critical issue. Proper use of WebDriverWait eliminates issues like this one.

Member

barancev commented Sep 6, 2017

No estimations. We don't consider this to be a critical issue. Proper use of WebDriverWait eliminates issues like this one.

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Sep 6, 2017

@barancev to my knowledge, that is not possible from the Perl bindings. And submitElement is a part of the official Selenium API, isn't it?

mgruner commented Sep 6, 2017

@barancev to my knowledge, that is not possible from the Perl bindings. And submitElement is a part of the official Selenium API, isn't it?

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Sep 6, 2017

Alternatively, WebDriver has the convenience method “submit” on every element. If you call this on an element within a form, WebDriver will walk up the DOM until it finds the enclosing form and then calls submit on that. (http://www.seleniumhq.org/docs/03_webdriver.jsp#selenium-webdriver-api-commands-and-operations)

mgruner commented Sep 6, 2017

Alternatively, WebDriver has the convenience method “submit” on every element. If you call this on an element within a form, WebDriver will walk up the DOM until it finds the enclosing form and then calls submit on that. (http://www.seleniumhq.org/docs/03_webdriver.jsp#selenium-webdriver-api-commands-and-operations)

@shs96c

This comment has been minimized.

Show comment
Hide comment
@shs96c

shs96c Sep 6, 2017

Member

Figuring out when the page load starts is a tricky problem. Since the submit is done using a pile of JS code, it's safe to assume that the JS has finished executing once the call returns, and we expect that the page loads have started too. The processing model of selenium means that the next request should wait until the current page is at the readyState expected by its page loading strategy.

Put another way, the drivers do a "best effort" to figure out if the page is going to reload, and the drivers also wait until they believe it's safe to process a command, but there's no way to guarantee that we successfully catch all the places where loads start. That's why most language bindings have the equivalent of the Wait class --- to handle just this kind of case.

For reference, "submit" is implemented as a JS shim. This simply walks up the DOM until it finds the FORM element, and then calls "submit()" on that. If you "click" on the submit button (as @andreastt implied) then you'll get the w3c behaviour, which includes a set of browser side checks to try and determine whether a page load will happen.

Member

shs96c commented Sep 6, 2017

Figuring out when the page load starts is a tricky problem. Since the submit is done using a pile of JS code, it's safe to assume that the JS has finished executing once the call returns, and we expect that the page loads have started too. The processing model of selenium means that the next request should wait until the current page is at the readyState expected by its page loading strategy.

Put another way, the drivers do a "best effort" to figure out if the page is going to reload, and the drivers also wait until they believe it's safe to process a command, but there's no way to guarantee that we successfully catch all the places where loads start. That's why most language bindings have the equivalent of the Wait class --- to handle just this kind of case.

For reference, "submit" is implemented as a JS shim. This simply walks up the DOM until it finds the FORM element, and then calls "submit()" on that. If you "click" on the submit button (as @andreastt implied) then you'll get the w3c behaviour, which includes a set of browser side checks to try and determine whether a page load will happen.

@shs96c shs96c closed this Sep 6, 2017

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Sep 6, 2017

@shs96c thank you very much for the clarification. Unfortunately, document.readyState is complete right after calling submitElement (just tested with FF 55.0.3). I don't believe that is intended, is it? We have no problem in waiting for the right readyState, but with the current situation there is no way of detecting that the load even started. That's precisely what this issue is about.
Is there anything else we can try to work around this?

mgruner commented Sep 6, 2017

@shs96c thank you very much for the clarification. Unfortunately, document.readyState is complete right after calling submitElement (just tested with FF 55.0.3). I don't believe that is intended, is it? We have no problem in waiting for the right readyState, but with the current situation there is no way of detecting that the load even started. That's precisely what this issue is about.
Is there anything else we can try to work around this?

@shs96c

This comment has been minimized.

Show comment
Hide comment
@shs96c

shs96c Sep 6, 2017

Member

The readyState is something that browser updates --- it's nothing to do with selenium, though we do rely on its value.

The best solution is to make use of the Wait class, like so:

Wait<WebDriver> wait = new WebDriverWait(driver, 10, TimeUnit.SECONDS);
wait.until(driver -> { /* Your check here */ });

There are some pre-prepared conditions for waiting in the ExpectedConditions class.

Member

shs96c commented Sep 6, 2017

The readyState is something that browser updates --- it's nothing to do with selenium, though we do rely on its value.

The best solution is to make use of the Wait class, like so:

Wait<WebDriver> wait = new WebDriverWait(driver, 10, TimeUnit.SECONDS);
wait.until(driver -> { /* Your check here */ });

There are some pre-prepared conditions for waiting in the ExpectedConditions class.

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Sep 6, 2017

@shs96c we already have a waiting strategy in place for submits. Essentially we wait for the page being loaded completely and all our code being executed, which is verified by accessing a JavaScript variable that our code sets at the end. This would include document.readyState verification. Unfortunately, this waiting fails now because right after the submit() it reports that the page has loaded.
So what else should we wait for?

mgruner commented Sep 6, 2017

@shs96c we already have a waiting strategy in place for submits. Essentially we wait for the page being loaded completely and all our code being executed, which is verified by accessing a JavaScript variable that our code sets at the end. This would include document.readyState verification. Unfortunately, this waiting fails now because right after the submit() it reports that the page has loaded.
So what else should we wait for?

@luke-hill

This comment has been minimized.

Show comment
Hide comment
@luke-hill

luke-hill Sep 6, 2017

Contributor

On our site we have a late_loading_css hash and the page title. Once both pass we're happy.

Contributor

luke-hill commented Sep 6, 2017

On our site we have a late_loading_css hash and the page title. Once both pass we're happy.

@jimevans

This comment has been minimized.

Show comment
Hide comment
@jimevans

jimevans Sep 6, 2017

Member

@mgruner If it's that big a deal, wait for the element you're calling submit() on to become stale (which guarantees the page reload has started), then fall into your "wait for page load" routine.

Member

jimevans commented Sep 6, 2017

@mgruner If it's that big a deal, wait for the element you're calling submit() on to become stale (which guarantees the page reload has started), then fall into your "wait for page load" routine.

@shs96c

This comment has been minimized.

Show comment
Hide comment
@shs96c

shs96c Sep 6, 2017

Member

@mgruner, unset the variable indicating the page is loaded before executing the submit.

Member

shs96c commented Sep 6, 2017

@mgruner, unset the variable indicating the page is loaded before executing the submit.

@mgruner

This comment has been minimized.

Show comment
Hide comment
@mgruner

mgruner Sep 7, 2017

Thanks for all suggestions.

mgruner commented Sep 7, 2017

Thanks for all suggestions.

@harvesh123

This comment has been minimized.

Show comment
Hide comment
@harvesh123

harvesh123 Oct 12, 2017

Hi I'm using selenium 3.6.0
FF -55.0
geckodriver v0.19.0

I'm also having same problem i'm running 2 test cases one by one but first test cases need time to realod but ff doesn't wait and start second test cases. can any one suggest.....please

harvesh123 commented Oct 12, 2017

Hi I'm using selenium 3.6.0
FF -55.0
geckodriver v0.19.0

I'm also having same problem i'm running 2 test cases one by one but first test cases need time to realod but ff doesn't wait and start second test cases. can any one suggest.....please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment