I have a simple html form, like this one
<!DOCTYPE html>
<html>
<body>
<form action="/Login/Authenticate" id="Loginform" method="post">
<label for="fname">User name:</label><br>
<input class="Txt_bx password" data-val="true" data-val-required="Enter Password" id="txtPassword" name="Log.password" type="text"><br>
<label for="lname">Password :</label><br>
<input class="Txt_bx urserName" data-val="true" data-val-required="Enter Username" id="txtusername" name="Log.username" type="password" value="">
</form>
</body>
</html>
I want to insert some text into the input class Txt_bx password and Txt_bx username without using selenium as it is too slow. Is there any other way I can do this?
Any help would be Appreciated!
-
dear @Heisenberg why didn't use jquery or js? and is this for testing? sorry for my language because English isn't my primary languagesachin kumara liyanage– sachin kumara liyanage2020年09月04日 16:17:56 +00:00Commented Sep 4, 2020 at 16:17
-
@sachinkumaraliyanage because I don't know jquery and js. I wanted to hack a simple html form using python, that's why I'm learning how to do so but I couldn't find how to do this.Heisenberg– Heisenberg2020年09月04日 16:19:50 +00:00Commented Sep 4, 2020 at 16:19
2 Answers 2
You could use the requests library for Python, and this page should help to introduce you to POST (as seen by the method tag on the form) requests in the library. You will need to POST to /Login/Authenticate, as it is the action of the form.
In your HTML code, log.Password and log.Username will be the dictionary's keys, and the values will be whatever values you want. For example:
data = {
"log.Username": "mynewusername",
"log.Password": "mynewpassword"
}
3 Comments
Try Using Requests
import requests
response = requests.post(
'http://url.com/Login/Authenticate',
data={
"Log.password": "password",
"Log.username": "username"
}
)
print(response.content) #get the response from whatever server
Don't forget to replace url.com with the actual domain