1

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 1

3

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&param2=value2');
return xhr.response;'''

result = driver.execute_script(jsrequest)
Sign up to request clarification or add additional context in comments.

3 Comments

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 :,
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?
You can construct the POST request in JavaScript as an XMLHttpRequest, then execute that script via Selenium. See edit to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.