Advertisement
InnovAnon-Inc

jalandhar-account-o_creat

Aug 6th, 2024
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 18.44 KB | Source Code | 0 0
  1. #! /usr/bin/env python
  2.  
  3. """
  4. Code Segment Commissioned by Team +91
  5. """
  6.  
  7.     @app.get("/jalandhar")
  8.     async def _punjab3(email            :str,
  9.                     password         :Optional[str]  =None,
  10.                     limit            :Optional[int]  =None,
  11.                     mean_arrival_rate:Optional[float]=None,
  12.     )->Response:#Union[Response,FileResponse]:
  13.         """
  14.        log me in! (Jalandar)
  15.        Use Case: One of their employees said to make an account
  16.        """
  17.         await logger.adebug('_punjab3 %s %s %s %s', email, password, limit, mean_arrival_rate)
  18.         _url:str = 'https://portal2.passportindia.gov.in/AppOnlineProject/user/RegistrationBaseAction?request_locale=en'
  19.         return await _login_helper(_punjab3_helper, _url, email, password, limit, mean_arrival_rate)
  20.  
  21.     def _punjab3_helper(driver:WebDriver, email:str, passwd:str, mean_arrival_rate:Optional[float])->Optional[str]:
  22.         """
  23.        demonstrate the punjab3 account creation sequence
  24.  
  25.        [cite](https://sqa.stackexchange.com/questions/45719/selenium-throws-movetargetoutofboundsexception-while-using-negative-value-in-the)
  26.        [cite](https://stackoverflow.com/questions/56085152/selenium-python-error-element-could-not-be-scrolled-into-view)
  27.        [cite](https://stackoverflow.com/questions/72460250/python-selenium-element-is-not-clickable-at-point-even-while-using-wait-until-el)
  28.        [cite](https://stackoverflow.com/questions/7867537/how-to-select-a-drop-down-menu-value-with-selenium-using-python)
  29.        [cite](https://stackoverflow.com/questions/45215992/how-to-get-img-src-in-string-in-selenium-using-python)
  30.        [cite](https://stackoverflow.com/questions/17361742/download-image-with-selenium-python)
  31.        """
  32.         logger.debug('_punjab3_helper %s %s', email, passwd)
  33.         assert isinstance(passwd,str)
  34.  
  35.         nonlocal timeout
  36.         #nonlocal solver
  37.  
  38.         logger.debug('looking for the office')
  39.         by     = By.XPATH
  40.         cond   = "//select[@aria-describedby='tibDesc']"
  41.         _office = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  42.         logger.debug('scrolling the office')
  43.         driver.execute_script('arguments[0].scrollIntoView();', _office)
  44.         try:
  45.             logger.debug('waiting for office to become visible')
  46.             _office = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  47.         except TimeoutException as e:
  48.             logger.exception(e)
  49.         try:
  50.             logger.debug('waiting for office to become clickable')
  51.             _office = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  52.         except TimeoutException as e:
  53.             logger.exception(e)
  54.         logger.debug('found the office')
  55.         #driver.execute_script("arguments[0].click();", _office)
  56.         ddelement = Select(_office)
  57.         ddelement.select_by_visible_text('Jalandhar')
  58.         logger.debug('entered office')
  59.  
  60.         logger.debug('looking for given name')
  61.         by     = By.XPATH
  62.         cond   = "//input[@aria-describedby='nameDesc']"
  63.         _givenName = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  64.         logger.debug('scrolling the given name')
  65.         driver.execute_script('arguments[0].scrollIntoView();', _givenName)
  66.         try:
  67.             logger.debug('waiting for given name to become visible')
  68.             _givenName = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  69.         except TimeoutException as e:
  70.             logger.exception(e)
  71.         try:
  72.             logger.debug('waiting for given name to become clickable')
  73.             _givenName = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  74.         except TimeoutException as e:
  75.             logger.exception(e)
  76.         logger.debug('found the given name')
  77.         #driver.execute_script("arguments[0].click();", _office)
  78.         ActionChains(driver).move_to_element(_givenName) .click(_givenName) .send_keys('Brute Four') .perform()
  79.         logger.debug('entered given name')
  80.         ActionChains(driver).move_to_element(_givenName) .click(_givenName) .send_keys(Keys.TAB) .perform()
  81.         logger.debug('pressed tab')
  82.  
  83.         logger.debug('looking for surname')
  84.         by     = By.XPATH
  85.         cond   = "//input[@aria-describedby='surnameDesc']"
  86.         _surname = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  87.         logger.debug('scrolling the surname')
  88.         driver.execute_script('arguments[0].scrollIntoView();', _surname)
  89.         try:
  90.             logger.debug('waiting for surname to become visible')
  91.             _surname = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  92.         except TimeoutException as e:
  93.             logger.exception(e)
  94.         try:
  95.             logger.debug('waiting for surname to become clickable')
  96.             _surname = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  97.         except TimeoutException as e:
  98.             logger.exception(e)
  99.         logger.debug('found the surname')
  100.         #driver.execute_script("arguments[0].click();", _office)
  101.         ActionChains(driver).move_to_element(_surname) .click(_surname) .send_keys('Singh') .perform()
  102.         logger.debug('entered surname')
  103.         ActionChains(driver).move_to_element(_surname) .click(_surname) .send_keys(Keys.TAB) .perform()
  104.         logger.debug('pressed tab')
  105.                
  106.         logger.debug('looking for dob')
  107.         by     = By.XPATH
  108.         cond   = "//input[@aria-describedby='dateformatDesc']"
  109.         _dob = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  110.         logger.debug('scrolling the dob')
  111.         driver.execute_script('arguments[0].scrollIntoView();', _dob)
  112.         try:
  113.             logger.debug('waiting for dob to become visible')
  114.             _dob = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  115.         except TimeoutException as e:
  116.             logger.exception(e)
  117.         try:
  118.             logger.debug('waiting for dob to become clickable')
  119.             _dob = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  120.         except TimeoutException as e:
  121.             logger.exception(e)
  122.         logger.debug('found the dob')
  123.         #driver.execute_script("arguments[0].click();", _dob)
  124.         ActionChains(driver).move_to_element(_dob) .click(_dob) .send_keys('30/04/1945') .perform()
  125.         logger.debug('entered dob')
  126.         ActionChains(driver).move_to_element(_dob) .click(_dob) .send_keys(Keys.TAB) .perform()
  127.         logger.debug('pressed tab')
  128.  
  129.         logger.debug('looking for email')
  130.         by     = By.XPATH
  131.         cond   = "//input[@aria-describedby='emailError']"
  132.         _email = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  133.         logger.debug('scrolling the email')
  134.         driver.execute_script('arguments[0].scrollIntoView();', _email)
  135.         try:
  136.             logger.debug('waiting for email to become visible')
  137.             _email = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  138.         except TimeoutException as e:
  139.             logger.exception(e)
  140.         try:
  141.             logger.debug('waiting for email to become clickable')
  142.             _email = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  143.         except TimeoutException as e:
  144.             logger.exception(e)
  145.         logger.debug('found the email')
  146.         #driver.execute_script("arguments[0].click();", _email)
  147.         ActionChains(driver).move_to_element(_email) .click(_email) .send_keys(email) .perform()
  148.         logger.debug('entered email')
  149.         ActionChains(driver).move_to_element(_email) .click(_email) .send_keys(Keys.TAB) .perform()
  150.         logger.debug('pressed tab')
  151.  
  152.         logger.debug('looking for same')
  153.         by     = By.XPATH
  154.         cond   = "//input[@id='emailloginSameyes']"
  155.         _same = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  156.         logger.debug('scrolling the same')
  157.         driver.execute_script('arguments[0].scrollIntoView();', _same)
  158.         try:
  159.             logger.debug('waiting for same to become visible')
  160.             _same = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  161.         except TimeoutException as e:
  162.             logger.exception(e)
  163.         try:
  164.             logger.debug('waiting for same to become clickable')
  165.             _same = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  166.         except TimeoutException as e:
  167.             logger.exception(e)
  168.         logger.debug('found the same')
  169.         #driver.execute_script("arguments[0].click();", _same)
  170.         ActionChains(driver).move_to_element(_same) .click(_same)  .perform()
  171.         logger.debug('entered same')
  172.         ActionChains(driver).move_to_element(_same) .click(_same) .send_keys(Keys.TAB) .perform()
  173.         logger.debug('pressed tab')
  174.  
  175.         logger.debug('looking for login')
  176.         by     = By.XPATH
  177.         cond   = "//input[@aria-describedby='loginIdError']"
  178.         _login = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  179.         logger.debug('scrolling the login')
  180.         driver.execute_script('arguments[0].scrollIntoView();', _login)
  181.         try:
  182.             logger.debug('waiting for login to become visible')
  183.             _login = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  184.         except TimeoutException as e:
  185.             logger.exception(e)
  186.         try:
  187.             logger.debug('waiting for login to become clickable')
  188.             _login = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  189.         except TimeoutException as e:
  190.             logger.exception(e)
  191.         logger.debug('found the login')
  192.         #driver.execute_script("arguments[0].click();", _login)
  193.         ActionChains(driver).move_to_element(_login) .click(_login) .send_keys(email) .perform()
  194.         logger.debug('entered login')
  195.         ActionChains(driver).move_to_element(_login) .click(_login) .send_keys(Keys.TAB) .perform()
  196.         logger.debug('pressed tab')
  197.  
  198.         logger.debug('looking for passwd')
  199.         by     = By.XPATH
  200.         cond   = "//input[@aria-describedby='pwdError']"
  201.         _passwd = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  202.         logger.debug('scrolling the passwd')
  203.         driver.execute_script('arguments[0].scrollIntoView();', _passwd)
  204.         try:
  205.             logger.debug('waiting for passwd to become visible')
  206.             _passwd = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  207.         except TimeoutException as e:
  208.             logger.exception(e)
  209.         try:
  210.             logger.debug('waiting for passwd to become clickable')
  211.             _passwd = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  212.         except TimeoutException as e:
  213.             logger.exception(e)
  214.         logger.debug('found the passwd')
  215.         #driver.execute_script("arguments[0].click();", _passwd)
  216.         ActionChains(driver).move_to_element(_passwd) .click(_passwd) .send_keys(passwd) .perform()
  217.         logger.debug('entered passwd')
  218.         ActionChains(driver).move_to_element(_passwd) .click(_passwd) .send_keys(Keys.TAB) .perform()
  219.         logger.debug('pressed tab')
  220.  
  221.         logger.debug('looking for confirm passwd')
  222.         by     = By.XPATH
  223.         cond   = "//input[@aria-describedby='confirmPwdError']"
  224.         _passwd = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  225.         logger.debug('scrolling the confirm passwd')
  226.         driver.execute_script('arguments[0].scrollIntoView();', _passwd)
  227.         try:
  228.             logger.debug('waiting for confirm passwd to become visible')
  229.             _passwd = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  230.         except TimeoutException as e:
  231.             logger.exception(e)
  232.         try:
  233.             logger.debug('waiting for confirm passwd to become clickable')
  234.             _passwd = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  235.         except TimeoutException as e:
  236.             logger.exception(e)
  237.         logger.debug('found the confirm passwd')
  238.         #driver.execute_script("arguments[0].click();", _passwd)
  239.         ActionChains(driver).move_to_element(_passwd) .click(_passwd) .send_keys(passwd) .perform()
  240.         logger.debug('entered confirm passwd')
  241.         ActionChains(driver).move_to_element(_passwd) .click(_passwd) .send_keys(Keys.TAB) .perform()
  242.         logger.debug('pressed tab')
  243.        
  244.         logger.debug('looking for hint question')
  245.         by     = By.XPATH
  246.         cond   = "//select[@aria-describedby='hintQuesError']"
  247.         _hintq = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  248.         logger.debug('scrolling the hint question')
  249.         driver.execute_script('arguments[0].scrollIntoView();', _hintq)
  250.         try:
  251.             logger.debug('waiting for hint question to become visible')
  252.             _hintq = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  253.         except TimeoutException as e:
  254.             logger.exception(e)
  255.         try:
  256.             logger.debug('waiting for hint question to become clickable')
  257.             _hintq = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  258.         except TimeoutException as e:
  259.             logger.exception(e)
  260.         logger.debug('found the hint question')
  261.         ddelement = Select(_hintq)
  262.         ddelement.select_by_visible_text('Birth City')
  263.         logger.debug('pressed tab')
  264.  
  265.         logger.debug('looking for hint answer')
  266.         by     = By.XPATH
  267.         cond   = "//input[@aria-describedby='hintAnsError']"
  268.         _hinta = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  269.         logger.debug('scrolling the hint answer')
  270.         driver.execute_script('arguments[0].scrollIntoView();', _hinta)
  271.         try:
  272.             logger.debug('waiting for hint answer to become visible')
  273.             _hinta = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  274.         except TimeoutException as e:
  275.             logger.exception(e)
  276.         try:
  277.             logger.debug('waiting for hint answer to become clickable')
  278.             _hinta = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  279.         except TimeoutException as e:
  280.             logger.exception(e)
  281.         logger.debug('found the hint answer')
  282.         #driver.execute_script("arguments[0].click();", _hinta)
  283.         ActionChains(driver).move_to_element(_hinta) .click(_hinta) .send_keys("I need a <redacted> and a pizza") .perform()
  284.         logger.debug('entered hint answer')
  285.         ActionChains(driver).move_to_element(_hinta) .click(_hinta) .send_keys(Keys.TAB) .perform()
  286.         logger.debug('pressed tab')
  287.  
  288.         logger.debug('looking for captcha')
  289.         by     = By.XPATH
  290.         cond   = "//img[@alt='Captcha']"
  291.         _captcha = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  292.         logger.debug('scrolling the captcha')
  293.         driver.execute_script('arguments[0].scrollIntoView();', _captcha)
  294.         try:
  295.             logger.debug('waiting for captcha to become visible')
  296.             _captcha = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  297.         except TimeoutException as e:
  298.             logger.exception(e)
  299.         logger.debug('found the captcha')
  300.  
  301.         contents = _captcha.screenshot_as_png # FIXME the handrolled-solver is janky
  302.         _bytes   = BytesIO(contents)          # probably LLM-<redacted>
  303.         img      = Image.open(_bytes)         # maybe we can fine-tune a model?
  304.         text     = image_to_string(img)
  305.         #text     = solver.solve_captcha(contents) # clever :/
  306.  
  307.         logger.debug('looking for ocr')
  308.         by     = By.XPATH
  309.         cond   = "//input[@aria-describedby='testError']"
  310.         _ocr = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  311.         logger.debug('scrolling the ocr')
  312.         driver.execute_script('arguments[0].scrollIntoView();', _ocr)
  313.         try:
  314.             logger.debug('waiting for ocr to become visible')
  315.             _ocr = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  316.         except TimeoutException as e:
  317.             logger.exception(e)
  318.         try:
  319.             logger.debug('waiting for ocr to become clickable')
  320.             _ocr = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  321.         except TimeoutException as e:
  322.             logger.exception(e)
  323.         logger.debug('found the ocr')
  324.         #driver.execute_script("arguments[0].click();", _ocr)
  325.         ActionChains(driver).move_to_element(_ocr) .click(_ocr) .send_keys(text)    .send_keys(Keys.ENTER) .perform()
  326.         logger.debug('entered ocr')
  327.  
  328.         #logger.debug('looking for register')
  329.         #by     = By.XPATH
  330.         #cond   = "//input[@value='Register']"
  331.         #_register = WebDriverWait(driver, timeout).until( EC.presence_of_element_located  ((by, cond)))
  332.         #logger.debug('scrolling the register')
  333.         #driver.execute_script('arguments[0].scrollIntoView();', _register)
  334.         #try:
  335.         #    logger.debug('waiting for register to become visible')
  336.         #    _register = WebDriverWait(driver, timeout).until( EC.visibility_of_element_located((by, cond)))
  337.         #except TimeoutException as e:
  338.         #    logger.exception(e)
  339.         #try:
  340.         #    logger.debug('waiting for register to become clickable')
  341.         #    _register = WebDriverWait(driver, timeout).until( EC.element_to_be_clickable      ((by, cond)))
  342.         #except TimeoutException as e:
  343.         #    logger.exception(e)
  344.         #logger.debug('found the register')
  345.         ##driver.execute_script("arguments[0].click();", _register)
  346.         #ActionChains(driver).move_to_element(_register) .click(_register) .perform()
  347.         #logger.debug('clicked register')
  348.  
  349.         # TODO how to know if successful
  350.  
  351.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement