I need to login to a website, however, it has a hidden recaptcha field that I cannot use send_keys (element not interactable). Is there any possibility of making a POST request with selenium or selenium requests?
1 Answer
With Python you should be able to use something like this:
webdriver = Firefox()
response = webdriver.request('POST', 'url', data={"x": "y"})
Alternatively, execute the POST request via JavaScript:
jsrequest = '''var xhr = new XMLHttpRequest();
xhr.open('POST', '{{URL}}', false);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send(param1=value¶m2=value2');
return xhr.response;'''
result = driver.execute_script(jsrequest)
3 Comments
Harrison Henri
Thanks for the quick response Josh, but apparently, when making the request this way, the browser window follows the following strange behavior: 1 - Opens in the url data :, 2 - Opens a tab on the home page of the website 3 - Close the tab and return to the date :,
Harrison Henri
Wouldn't it be possible to make the request and use the session after the request for selenium already access the page with the session started and the user logged in?
Josh Ray
You can construct the
POST request in JavaScript as an XMLHttpRequest, then execute that script via Selenium. See edit to the answer.