Skip to content

Instantly share code, notes, and snippets.

@Tuhin-thinks
Created March 30, 2024 21:23
Show Gist options
  • Save Tuhin-thinks/3da86dbad802ac5323e5cc78e0ea78c6 to your computer and use it in GitHub Desktop.
Save Tuhin-thinks/3da86dbad802ac5323e5cc78e0ea78c6 to your computer and use it in GitHub Desktop.
import time
from typing import Dict
import pyautogui as pag
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
def fill_form_tab_seq(form_data: Dict):
# reload
# tab -> account number (fill acc number)
# shift + tab -> env (non-prod , since coming from below) :: select non-prod | prod using arrow
# shift + tab -> region (press ENTER + ENTER) to select the first region available)
# shift + tab -> cloud provider
# tab x 4 -> request type (select using arrow)
# tab -> type of request is this for (text field, write something)
# tab -> submit button (click) --> submit the form
# account number
pag.press("tab")
pag.typewrite(form_data["account_number"])
# env
pag.hotkey("shift", "tab")
pag.press("up") # selecting non-prod
# region
pag.hotkey("shift", "tab")
pag.press("enter", presses=2) # select the only 1 choice
# cloud provider
pag.hotkey("shift", "tab")
pag.press("enter", presses=2) # select the only 1 choice
# request type
pag.press("tab", presses=4)
pag.press("up") # select the first choice
# type of request is this for :: text field
pag.press("tab")
pag.press("Something I am writing for testing this automation....")
# submit button
pag.press("tab")
# pag.press("enter") # TODO: enable to submit the form
def create_chrome_driver_session():
# create a new chrome session
driver_path = ChromeDriverManager().install()
service = Service(driver_path)
# chrome profile path
options = webdriver.ChromeOptions()
user_data_dir = r"/home/tuhin/.config/google-chrome/"
options.add_argument(f"user-data-dir={user_data_dir}")
profile_name = "Default"
options.add_argument(f"profile-directory={profile_name}")
options.add_argument("--start-maximized")
options.add_argument("--disable-extensions")
options.add_argument("--disable-popup-blocking")
options.add_argument("--disable-infobars")
options.add_argument("--no-sandbox")
driver = webdriver.Chrome(options=options)
return driver
def open_url(driver, url):
driver.get(url)
time.sleep(3)
form_data = {"account_number": "123456"}
# fill the form
fill_form_tab_seq(form_data)
time.sleep(30) # TODO: remove this, only added for testing
def main():
driver = create_chrome_driver_session()
url = "https://mail.google.com/"
open_url(driver, url)
driver.quit()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment