Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to start with a POST request using Selenium?

Tags:

selenium

I'm trying to start a Selenium test with a POST request to my application.

Instead of a simple open(/startpoint)

I would like to do something like open(/startpoint, stuff=foo,stuff2=bar)

Is there any way to do that?

I'm asking this because the original page which posts to this start point depends on external providers that are often offline (development environment) and so will often fail too early (and are not the subject of the test)


I guess sending data as GET would work too. I would just prefer using a POST method.

like image 458
Romuald Brunet Avatar asked Apr 14 '11 09:04

Romuald Brunet


People also ask

Can you use Selenium with requests?

Extends Selenium WebDriver classes to include the request function from the Requests library, while doing all the needed cookie and request headers handling.

What is the get () method used for in Selenium?

The get command launches a new browser and opens the given URL in your Webdriver. It simply takes the string as your specified URL and opens it for testing purposes. If you are using Selenium IDE, it is similar to open command.


1 Answers

If you are using Python selenium bindings, nowadays, there is an extension to selenium - selenium-requests:

Extends Selenium WebDriver classes to include the request function from the Requests library, while doing all the needed cookie and request headers handling.

Example:

from seleniumrequests import Firefox  webdriver = Firefox() response = webdriver.request('POST', 'url here', data={"param1": "value1"}) print(response) 
like image 176
alecxe Avatar answered Sep 20 '22 02:09

alecxe