vendredi 8 avril 2022

Fill or ignore required random field with selenium python

I am practicing with selenium to log into a website and grab the mortage ticket (print/save/download it as pdf).

The logging page is as follows:

Field 1: Contract number

Field 2: National user-id

Botton: Botton to validate the contract

Field 3: Requests some aleatory personal info (day of birh, mother's name, zip code, National Health ID, voter registration etc.) each time the page is accessed/refreshed

When I log to it (every month) throughout the user page, when it comes to some aleatory info that I don't know by heart (such as National Heatlh ID or voter registration), I refresh the page until it brings me some easy to remember info(phone number, zipcode, etc.).

What can I do to go through this last field that requests personal information in a random way(some that I know by heart, others I do not)?

The website code referring to the 3rd field is as follows. The name="zipCode" part is the one that keeps changing value each time the page is refreshed.

input id="aleatoryField" class="mat-input-element mat-form-field-autofill-control 
ng-tns-c4-1 cdk-text-field-autofill-monitored ng-dirty ng-invalid ng-touched" 
_ngcontent-iqu-c4="" autocomplete="off" 
formcontrolname="aleatoryField" inputmode="decimal" matinput=""
pattern="[0-9]*" required="" name="zipCode" placeholder="Zip Code"
aria-describedby="mat-error-2" aria-invalid="true" aria-required="true"


# MY CURRENT CODE

from selenium import webdriver

driver = webdriver.Firefox(executable_path="./geckodriver.exe" )

# open the website
driver.get("https://www.habitacaodigital.caixa.gov.br/acesso-cliente")

# FIELD 1: contract info
contract = driver.find_element_by_id("contract")
national_id = driver.find_element_by_id("nationalId")

# FIELD 2: filling the contract info
contract.send_keys("123")
national_id.send_keys("321")

# botton
validate_contract = driver.find_element_by_id("validate_contract")
validate_contract.click()

# FIELD 3: aleatory personal info field (cellphone number, zip code, day of birth, mother's name...)
aleatory_field = driver.find_element_by_id("aleatoryField")
campoAleatorio.send_keys("HOW TO DEAL WITH THIS PART OVER HERE?")```




Aucun commentaire:

Enregistrer un commentaire