S
S
Sergei Erm2017-05-12 12:08:49
Python
Sergei Erm, 2017-05-12 12:08:49

Python Request: how to log in and click the "onclick" button?

Good afternoon, there is a hitch here about authorization. There is a site in Java and ajax authorization. At the entrance, a certificate is installed as a login, requests coped with this, but when entering a password, I don’t know how to give a request to press a button.

What to specify in the payload dictionary for pressing the login button ? (The html code of the button is below.)

And how to work with xpath?

<input type="password" autocomplete="off"
 size="0" name="passwordField" onchange="" 
class=".LoginText" title="Пароль" id="passwordField">
===
<button type="submit" onclick="submitForm('DefaultFormName',1,
{'_FORM_SUBMIT_BUTTON':'SubmitButton0OGtbcTW'});return false"
style="background-image:url(/OA_HTML/cabo/images/swan/btn-bg1.gif)"
class="x7g" title="Вход" id="SubmitButton">Вход</button>


import requests
    cert =('cert','key')
    password = "qwerty123"
    auths ={'passwordField':password}
    URL = "htтps://tender.sk.kz/OA_HTML/AppsLogin"
    s = requests.Session()
    r = s.get(URL, cert=cert, headers=headers, verify=False)
    auth_page = r.url
    r = s.post(auth_page, headers=headers, data=data)

KUPB0.png

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom, 2017-05-26
@hprot

Selenium webdriver is used to work with the front. With the requests library, you only send http requests and it is suitable for testing api and back, but not the front.
But selenium has all the necessary goodies for working with xpath and selectors. Here is an example code:

from selenium import webdriver

 driver = webdriver.Chrome()
    driver.get('#URL')
    username = driver.find_element_by_css_selector("input#username")
    username.click()
    username.send_keys('#Login')
    password = driver.find_element_by_css_selector("input#password")
    password.click()
    password.send_keys('11111')
    submit = driver.find_element_by_css_selector("input#kc-login")
    submit.click()
    time.sleep(3)
    activate_btn = driver.find_element_by_xpath(activate_xpath)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question