Issue
The task is to automatically fill out the application form below using Python.
I just can't figure out how to fill out the form to enter the phone number. Last name, first name and mail are randomly filled from the txt file. TIN is randomly generated in the required range. We need to help solve the problem with filling in the phone number from the txt file.
Below is my code:
import time
import random
from selenium import webdriver
browser = webdriver.Firefox(executable_path = 'C:\Program Files\geckodriver-v0.30.0\geckodriver.exe')
browser.get("http://nrpgov.ru/")
xpath = '/html/body/form/div[4]/div/div/div/div[4]/div[1]/div[2]/a'
browser.find_element_by_xpath(xpath).click()
surname_xpath = '/html/body/form/div[7]/div/div/div[2]/div/div/table/tbody/tr[1]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr/td/input'
lastname = open('surnames.txt', encoding='utf-8').readlines()
browser.find_element_by_xpath(surname_xpath).send_keys(random.choice(lastname))
name_xpath = '/html/body/form/div[7]/div/div/div[2]/div/div/table/tbody/tr[2]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr/td/input'
name = open('boys.txt', encoding='utf-8').readlines()
browser.find_element_by_xpath(name_xpath).send_keys(random.choice(name))
inn_xpath = '/html/body/form/div[7]/div/div/div[2]/div/div/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr/td/input'
inn_random = random.randint(1000000000, 9999999999)
browser.find_element_by_xpath(inn_xpath).send_keys(inn_random)
number_xpath = '/html/body/form/div[7]/div/div/div[2]/div/div/table/tbody/tr[5]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr/td/input'
browser.find_element_by_xpath(number_xpath).send_keys('9293454545')
email_xpath = '/html/body/form/div[7]/div/div/div[2]/div/div/table/tbody/tr[6]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr/td/input'
mails = open('mails.txt', encoding='utf-8').readlines()
browser.find_element_by_xpath(email_xpath).send_keys(random.choice(mails))
send_xpath = '/html/body/form/div[7]/div/div/div[3]/div/div/span'
browser.find_element_by_xpath(send_xpath).click()
Solution
I got your code working by simply clicking the element before using send_key
number_xpath = '/html/body/form/div[7]/div/div/div[2]/div/div/table/tbody/tr[5]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/table/tbody/tr/td/input'
browser.find_element_by_xpath(number_xpath).click()
browser.find_element_by_xpath(number_xpath).send_keys('9293454545')
Answered By - JustOscarJ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.