fill the field of refresh

This commit is contained in:
PAN Lei
2022-05-19 14:28:40 +02:00
parent 20e1fdd4a6
commit 82f44e589f
2 changed files with 32 additions and 17 deletions
+27 -16
View File
@@ -29,7 +29,7 @@ OTP_TIMEOUT = 240
def get_random_wait_time() -> float:
wait_time = random.randint(0, 10) / 10.0 * 5
wait_time = random.randint(0, 10) / 10.0 * 1
return wait_time
@@ -41,7 +41,7 @@ class Tls(threading.local):
class CommandorPage:
tls = Tls()
def __init__(self, contact: ContactPojo, store_type=0, proxy_type = 0):
def __init__(self, contact: ContactPojo, store_type=0, proxy_type=0):
self.otp_value = None
self.logger = logging.getLogger("CommandorPage")
self.is_finished = False
@@ -86,13 +86,7 @@ class CommandorPage:
"username": proxy_username,
"password": params.PROXY_PASSWORD
}
self._setName(self.contact.last_name, self.contact.first_name)
self._setPhoneCountryAndStore()
self._setPhoneNumber(self.contact.phone)
self._set_email(self.contact.mail)
self.setIdNumber(self.contact.passport)
#
self._checkCgu()
self.fill_fields()
# wait for sms_code field
# self.clickOnValidBtn()
self.thread_event = e
@@ -117,6 +111,15 @@ class CommandorPage:
self.logger.info("timeout")
self.termine()
def fill_fields(self):
self._set_name(self.contact.last_name, self.contact.first_name)
self._setPhoneCountryAndStore()
self._setPhoneNumber(self.contact.phone)
self._set_email(self.contact.mail)
self.setIdNumber(self.contact.passport)
#
self._checkCgu()
def start_browser(self, proxy, pwright, device) -> Union[str, None]:
try:
self.browser = pwright.webkit.launch(headless=False, timeout=90000, proxy=proxy)
@@ -151,6 +154,8 @@ class CommandorPage:
self.logger.info("page loaded")
# self.logger.info("content is " + self.page.content())
self.logger.info("url is " + self.page.url)
if self.page.url == RDV_URL:
self.fill_fields()
message = self.page.content()
if CONFIRMED_MESSAGE in message:
# publish the successful message
@@ -183,14 +188,18 @@ class CommandorPage:
except Exception as error:
self.logger.error(error)
def _setName(self, lastName, firstName):
def _set_name(self, lastName, firstName):
time.sleep(get_random_wait_time())
try:
self.page.evaluate("""(name)=> {
document.getElementById("surname").focus();
document.getElementById("surname").value = name.lastName;
self.page.evaluate("""(name)=> {
let surname = document.getElementById("surname");
if(surname.value.length == 0){
surname.focus();
surname.value = name.lastName;
document.getElementById("name").focus();
document.getElementById("name").value = name.firstName}""", {'lastName': lastName, 'firstName': firstName})
document.getElementById("name").value = name.firstName
}}
""", {'lastName': lastName, 'firstName': firstName})
except Exception as error:
self.logger.error(error)
@@ -224,8 +233,10 @@ class CommandorPage:
time.sleep(get_random_wait_time())
try:
self.page.evaluate("""(email)=>{
document.getElementById("email").focus();
document.getElementById("email").value = email;}""", email)
let emailElement = document.getElementById("email")
if(emailElement.value.length == 0){
emailElement.focus();
document.getElementById("email").value = email;}}""", email)
except Exception as error:
self.logger.error(error)