With selenium, you can execute arbitrary Javascript, including programmatically submitting the form .
The simplest JS implementation with Selenium Java:
if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor) driver).executeScript("alert('hello world');"); }
and with Javascript you can create a POST request, set the necessary parameters and HTTP headers and send it.
var xhr = new XMLHttpRequest(); xhr.open('POST', 'http://httpbin.org/post', true); xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhr.onload = function () { alert(this.responseText); }; xhr.send('login=test&password=test');
If you need to pass the response text to selenium, and instead of alert(this.responseText) use return this.responseText and assign the result of executeScript () to the java variable.
ccpizza
source share