How to wait for the Form submit answer in Selenium?

Viewed 23

I have a Selenium Test and in the test I am clicking on a submit button inside a form like following:

WebElement form = someContainerElement.findElement(By.cssSelector("form"));
form.submit():

Next I am refreshing the page manually by calling the same url again like following:

String url = customFunctionToBuildUrlFromPath("some/custom/page");
webDriver.get(url);

By the way, the webDriver is of type RemoteWebDriver. Next I am just testing a few webelements for example if they do exist or not. Everything works fine locally. On gitlab Pipleine it doesn't. On the pipeline it only works if i add Thread.sleep(3000) it also works on the pipeline.

So I guess I have to wait until the server has processed the post request. Locally it is fast enough but the gitlab Runner is not fast enought.

➡️ So I need to wait until the server sends the answer of the post request or the page is at least refreshed. How do you wait in Selenium for the answer of a form submit?

I tried to use WebDriverWait it doesn't seem like there is something like WebDriverWait.until(PageRefresh)

1 Answers

It looks like this is a feature selenium tries but can not offer as it is very depended on the actual implementation of the site. As issue was made that has very promising solutions for you. Personally i would try the solution of jimevans first

Related