I've been looking into a flaky Autofill Test (AutofillTest.ProfilesNotMergedWhenNoMinAddressData) and I seem to be having trouble executing some JavaScript before a page is fully loaded which is causing some flakiness.
The flake occurs in FillFormAndSubmit, which loads a page via ui_test_utils::NavigateToURL then uses some JavaScript to fill the form and submit it. When the test fails it is because the JavaScript fails to find any of the document elements (getElementById returns null). I added some logs and when the test fails, NavigateToURL seems to have returned before the onload function in the html page is executed. This seems to suggest that ui_test_utils::NavigateToURL is returning before the page is fully done loading.
Looking at NavigateToURL, it seems to support returning only once the page has finished loading (I'm calling ui_test_utils::NavigateToURL(browser(), url)), but since the JavaScript is failing to find an element it seems like this isn't the case.
Looking around the code base, it seems to be assumed that NavigateToURL will wait until the page is fully loaded, like I need. Is there something else I need to listen to if I want to ensure all the elements will be visible to my JavaScript, am I using NavigateToURL incorrectly, or is there some weird bug I might be hitting in it?
Thanks in advance for any help,
C#