There is a page on which there are about 15 input fields, each is taken in the form tags.

I select all input fields in Selenium:

List<WebElement> formInput = driver.findElements(By.tagName("input")); 

and ask them the value:

  int i = 0; for(WebElement element: formInput){ ((JavascriptExecutor)driver) .executeScript("document.getElementsByTagName('input')["+i+"].value='TEST'", element); i++; } 

Now I need to submit each form, but the problem is that when the form is submitted, it redirects to the page as: site.com/SaveResultId=xxx

And Selenium can no longer work with the following input, because it throws out Exception (which is logical since there are no input on the result page)

Is there any solution to add all fields one by one?

ideally add element.submit(); to the loop element.submit();

  • The answer: no way. One form - one submit. Everything is logical. Accordingly, for each form you need to return to the page with the form, fill it in, send, process the result. And so for each form. - Mikhail Rebrov
  • you can still try to do it not by means of selenium ... but simply form a POST request, manually send it and process the response. - Mikhail Rebrov
  • To form a request is also an option, is it possible with the help of Selenium to select all inputs in the form (including hiding) with the value to form a request in okhttp or curl? - Andrei
  • @ Mikhail Rebrov probably know something like that before Selenium, the main task is to find forms and submit them - Andrey
  • one
    then retrieve data using selenium and form and send requests yourself ... or study asynchronous requests with the help of which new data is loaded and, if possible, execute them yourself and get everything you need. - Mikhail Rebrov

0