Sending POST variables using selenium

11,635 views
Skip to first unread message

Shaun Wiseman

unread,
Aug 9, 2012, 10:47:41 AM8/9/12
to seleniu...@googlegroups.com
Hi all,

       I need to send some POST information in a web test. Is this possible? I can give examples if needed.

Thanks
Shaun

Simo

unread,
Aug 9, 2012, 11:01:20 AM8/9/12
to seleniu...@googlegroups.com
Would you please give more details of what you are looking for and be more specific so that we can help.

Shaun Wiseman

unread,
Aug 9, 2012, 11:15:15 AM8/9/12
to seleniu...@googlegroups.com
Of course my friend,
I want to post this Data-> customer=0%2CALL&Name=&username=Test&forename=&surname=&Role=&active=true&_target1=Search&_page=0

To this Site-> http://sitename/external/user/search.htm

Its a security test and i was using HackBar to do it originally but web driver wont allow you to interact with these plug-ins.
The Idea is to be logged on to the site and create a new user and sign yourself in by sending these requests. But I have no idea how to do it with web driver I wanted to know if it is possible?

ankit

unread,
Aug 9, 2012, 11:43:43 AM8/9/12
to seleniu...@googlegroups.com
If you just want to test whether the POST request works correctly, you could use a command line tool like cURL to do the job. I don't think its related to selenium unless you have a form and a submit button on a website that you want to test through a browser.

On Thursday, August 9, 2012 10:47:41 AM UTC-4, Shaun Wiseman wrote:

Simo

unread,
Aug 9, 2012, 11:45:00 AM8/9/12
to seleniu...@googlegroups.com
It is possible using Selenium Web Driver, but i think the easiest way is to use Selenium IDE

With Selenium IDE you can record the process of creation of new user and logging in to the site, hen you can play this scenario automatically.

Darrell Grainger

unread,
Aug 9, 2012, 2:37:18 PM8/9/12
to seleniu...@googlegroups.com
I agree with ankit. WebDriver is for simulating a user interacting with a web browser. As a hacker trying to attack your site with HTTP POST requests I'm going to use curl or something similar.

If you want to have all the code in one place or mix WebDriver tests with HTTP POST requests then add the libcurl library to your project and call it rather than running curl.  http://curl.haxx.se/libcurl/.

Krishnan Mahadevan

unread,
Aug 10, 2012, 1:55:26 AM8/10/12
to seleniu...@googlegroups.com
Shaun,

You could also try to do something like this :

After you have logged into your site : http://sitename/external/user/search.htm

Use javascript to create a <form></form>, append it to the page, and then use the regular methods within WebElement to click/submit etc.,

String html =   "<form method=post action=http://sitename/external/user/search.htm>" +
"<input type=hidden name=customer value=0>" +
"<input type=hidden name=Name value=">" +
"<input type=submit name=METHOD value=mysubmitbutton>" +
"</form>";
String script = "var h1 = document.createElement('div'); " + "h1.innerHTML=\"" + html + "\"; document.body.appendChild(h1)";
driver.executeScript(html);



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/5OEFA1PRrAoJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages