Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- """
- Code Segment Commissioned by Team +91
- """
- @app.get("/jalandhar")
- async def _punjab3(email :str,
- password :Optional[str] =None,
- limit :Optional[int] =None,
- mean_arrival_rate:Optional[float]=None,
- )->Response:#Union[Response,FileResponse]:
- """
- log me in! (Jalandar)
- Use Case: One of their employees said to make an account
- """
- await logger.adebug('_punjab3 %s %s %s %s', email, password, limit, mean_arrival_rate)
- _url:str = 'https://portal2.passportindia.gov.in/AppOnlineProject/user/RegistrationBaseAction?request_locale=en'
- return await _login_helper(_punjab3_helper, _url, email, password, limit, mean_arrival_rate)
- def _punjab3_helper(driver:WebDriver, email:str, passwd:str, mean_arrival_rate:Optional[float])->Optional[str]:
- """
- demonstrate the punjab3 account creation sequence
- [cite](https://sqa.stackexchange.com/questions/45719/selenium-throws-movetargetoutofboundsexception-while-using-negative-value-in-the)
- [cite](https://stackoverflow.com/questions/56085152/selenium-python-error-element-could-not-be-scrolled-into-view)
- [cite](https://stackoverflow.com/questions/72460250/python-selenium-element-is-not-clickable-at-point-even-while-using-wait-until-el)
- [cite](https://stackoverflow.com/questions/7867537/how-to-select-a-drop-down-menu-value-with-selenium-using-python)
- [cite](https://stackoverflow.com/questions/45215992/how-to-get-img-src-in-string-in-selenium-using-python)
- [cite](https://stackoverflow.com/questions/17361742/download-image-with-selenium-python)
- """
- logger.debug('_punjab3_helper %s %s', email, passwd)
- assert isinstance(passwd,str)
- nonlocal timeout
- #nonlocal solver
- logger.debug('looking for the office')
- by = By.XPATH
- cond = "//select[@aria-describedby='tibDesc']"
- _office = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the office')
- driver.execute_script('arguments[0].scrollIntoView();', _office)
- try:
- logger.debug('waiting for office to become visible')
- _office = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for office to become clickable')
- _office = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the office')
- #driver.execute_script("arguments[0].click();", _office)
- ddelement = Select(_office)
- ddelement.select_by_visible_text('Jalandhar')
- logger.debug('entered office')
- logger.debug('looking for given name')
- by = By.XPATH
- cond = "//input[@aria-describedby='nameDesc']"
- _givenName = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the given name')
- driver.execute_script('arguments[0].scrollIntoView();', _givenName)
- try:
- logger.debug('waiting for given name to become visible')
- _givenName = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for given name to become clickable')
- _givenName = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the given name')
- #driver.execute_script("arguments[0].click();", _office)
- ActionChains(driver).move_to_element(_givenName) .click(_givenName) .send_keys('Brute Four') .perform()
- logger.debug('entered given name')
- ActionChains(driver).move_to_element(_givenName) .click(_givenName) .send_keys(Keys.TAB) .perform()
- logger.debug('pressed tab')
- logger.debug('looking for surname')
- by = By.XPATH
- cond = "//input[@aria-describedby='surnameDesc']"
- _surname = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the surname')
- driver.execute_script('arguments[0].scrollIntoView();', _surname)
- try:
- logger.debug('waiting for surname to become visible')
- _surname = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for surname to become clickable')
- _surname = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the surname')
- #driver.execute_script("arguments[0].click();", _office)
- ActionChains(driver).move_to_element(_surname) .click(_surname) .send_keys('Singh') .perform()
- logger.debug('entered surname')
- ActionChains(driver).move_to_element(_surname) .click(_surname) .send_keys(Keys.TAB) .perform()
- logger.debug('pressed tab')
- logger.debug('looking for dob')
- by = By.XPATH
- cond = "//input[@aria-describedby='dateformatDesc']"
- _dob = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the dob')
- driver.execute_script('arguments[0].scrollIntoView();', _dob)
- try:
- logger.debug('waiting for dob to become visible')
- _dob = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for dob to become clickable')
- _dob = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the dob')
- #driver.execute_script("arguments[0].click();", _dob)
- ActionChains(driver).move_to_element(_dob) .click(_dob) .send_keys('30/04/1945') .perform()
- logger.debug('entered dob')
- ActionChains(driver).move_to_element(_dob) .click(_dob) .send_keys(Keys.TAB) .perform()
- logger.debug('pressed tab')
- logger.debug('looking for email')
- by = By.XPATH
- cond = "//input[@aria-describedby='emailError']"
- _email = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the email')
- driver.execute_script('arguments[0].scrollIntoView();', _email)
- try:
- logger.debug('waiting for email to become visible')
- _email = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for email to become clickable')
- _email = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the email')
- #driver.execute_script("arguments[0].click();", _email)
- ActionChains(driver).move_to_element(_email) .click(_email) .send_keys(email) .perform()
- logger.debug('entered email')
- ActionChains(driver).move_to_element(_email) .click(_email) .send_keys(Keys.TAB) .perform()
- logger.debug('pressed tab')
- logger.debug('looking for same')
- by = By.XPATH
- cond = "//input[@id='emailloginSameyes']"
- _same = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the same')
- driver.execute_script('arguments[0].scrollIntoView();', _same)
- try:
- logger.debug('waiting for same to become visible')
- _same = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for same to become clickable')
- _same = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the same')
- #driver.execute_script("arguments[0].click();", _same)
- ActionChains(driver).move_to_element(_same) .click(_same) .perform()
- logger.debug('entered same')
- ActionChains(driver).move_to_element(_same) .click(_same) .send_keys(Keys.TAB) .perform()
- logger.debug('pressed tab')
- logger.debug('looking for login')
- by = By.XPATH
- cond = "//input[@aria-describedby='loginIdError']"
- _login = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the login')
- driver.execute_script('arguments[0].scrollIntoView();', _login)
- try:
- logger.debug('waiting for login to become visible')
- _login = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for login to become clickable')
- _login = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the login')
- #driver.execute_script("arguments[0].click();", _login)
- ActionChains(driver).move_to_element(_login) .click(_login) .send_keys(email) .perform()
- logger.debug('entered login')
- ActionChains(driver).move_to_element(_login) .click(_login) .send_keys(Keys.TAB) .perform()
- logger.debug('pressed tab')
- logger.debug('looking for passwd')
- by = By.XPATH
- cond = "//input[@aria-describedby='pwdError']"
- _passwd = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the passwd')
- driver.execute_script('arguments[0].scrollIntoView();', _passwd)
- try:
- logger.debug('waiting for passwd to become visible')
- _passwd = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for passwd to become clickable')
- _passwd = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the passwd')
- #driver.execute_script("arguments[0].click();", _passwd)
- ActionChains(driver).move_to_element(_passwd) .click(_passwd) .send_keys(passwd) .perform()
- logger.debug('entered passwd')
- ActionChains(driver).move_to_element(_passwd) .click(_passwd) .send_keys(Keys.TAB) .perform()
- logger.debug('pressed tab')
- logger.debug('looking for confirm passwd')
- by = By.XPATH
- cond = "//input[@aria-describedby='confirmPwdError']"
- _passwd = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the confirm passwd')
- driver.execute_script('arguments[0].scrollIntoView();', _passwd)
- try:
- logger.debug('waiting for confirm passwd to become visible')
- _passwd = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for confirm passwd to become clickable')
- _passwd = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the confirm passwd')
- #driver.execute_script("arguments[0].click();", _passwd)
- ActionChains(driver).move_to_element(_passwd) .click(_passwd) .send_keys(passwd) .perform()
- logger.debug('entered confirm passwd')
- ActionChains(driver).move_to_element(_passwd) .click(_passwd) .send_keys(Keys.TAB) .perform()
- logger.debug('pressed tab')
- logger.debug('looking for hint question')
- by = By.XPATH
- cond = "//select[@aria-describedby='hintQuesError']"
- _hintq = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the hint question')
- driver.execute_script('arguments[0].scrollIntoView();', _hintq)
- try:
- logger.debug('waiting for hint question to become visible')
- _hintq = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for hint question to become clickable')
- _hintq = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the hint question')
- ddelement = Select(_hintq)
- ddelement.select_by_visible_text('Birth City')
- logger.debug('pressed tab')
- logger.debug('looking for hint answer')
- by = By.XPATH
- cond = "//input[@aria-describedby='hintAnsError']"
- _hinta = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the hint answer')
- driver.execute_script('arguments[0].scrollIntoView();', _hinta)
- try:
- logger.debug('waiting for hint answer to become visible')
- _hinta = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for hint answer to become clickable')
- _hinta = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the hint answer')
- #driver.execute_script("arguments[0].click();", _hinta)
- ActionChains(driver).move_to_element(_hinta) .click(_hinta) .send_keys("I need a <redacted> and a pizza") .perform()
- logger.debug('entered hint answer')
- ActionChains(driver).move_to_element(_hinta) .click(_hinta) .send_keys(Keys.TAB) .perform()
- logger.debug('pressed tab')
- logger.debug('looking for captcha')
- by = By.XPATH
- cond = "//img[@alt='Captcha']"
- _captcha = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the captcha')
- driver.execute_script('arguments[0].scrollIntoView();', _captcha)
- try:
- logger.debug('waiting for captcha to become visible')
- _captcha = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the captcha')
- contents = _captcha.screenshot_as_png # FIXME the handrolled-solver is janky
- _bytes = BytesIO(contents) # probably LLM-<redacted>
- img = Image.open(_bytes) # maybe we can fine-tune a model?
- text = image_to_string(img)
- #text = solver.solve_captcha(contents) # clever :/
- logger.debug('looking for ocr')
- by = By.XPATH
- cond = "//input[@aria-describedby='testError']"
- _ocr = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- logger.debug('scrolling the ocr')
- driver.execute_script('arguments[0].scrollIntoView();', _ocr)
- try:
- logger.debug('waiting for ocr to become visible')
- _ocr = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- try:
- logger.debug('waiting for ocr to become clickable')
- _ocr = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- except TimeoutException as e:
- logger.exception(e)
- logger.debug('found the ocr')
- #driver.execute_script("arguments[0].click();", _ocr)
- ActionChains(driver).move_to_element(_ocr) .click(_ocr) .send_keys(text) .send_keys(Keys.ENTER) .perform()
- logger.debug('entered ocr')
- #logger.debug('looking for register')
- #by = By.XPATH
- #cond = "//input[@value='Register']"
- #_register = WebDriverWait(driver, timeout).until( EC.presence_of_element_located ((by, cond)))
- #logger.debug('scrolling the register')
- #driver.execute_script('arguments[0].scrollIntoView();', _register)
- #try:
- # logger.debug('waiting for register to become visible')
- # _register = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
- #except TimeoutException as e:
- # logger.exception(e)
- #try:
- # logger.debug('waiting for register to become clickable')
- # _register = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable ((by, cond)))
- #except TimeoutException as e:
- # logger.exception(e)
- #logger.debug('found the register')
- ##driver.execute_script("arguments[0].click();", _register)
- #ActionChains(driver).move_to_element(_register) .click(_register) .perform()
- #logger.debug('clicked register')
- # TODO how to know if successful
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement