Skip to content

Instantly share code, notes, and snippets.

@ganigithub
Last active June 27, 2022 15:18
Show Gist options
  • Save ganigithub/4da8733e3e2c8de08d8d7d5464d7ec4d to your computer and use it in GitHub Desktop.
Save ganigithub/4da8733e3e2c8de08d8d7d5464d7ec4d to your computer and use it in GitHub Desktop.
from selenium import webdriver
from pyotp import TOTP
from time import sleep
def login(self, webdriver_path, url, user_id, pwd, totp):
"""
This function will login to zerodha account with inspect element opened.
"""
service = webdriver.chrome.service.Service(webdriver_path)
service.start()
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
options.add_argument("start-maximized")
options.add_argument("--auto-open-devtools-for-tabs")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options = options.to_capabilities()
driver = webdriver.Remote(service.service_url, options)
driver.maximize_window
driver.get(url)
sleep(1)
username = driver.find_element_by_xpath("//input[@type = 'text']")
username.send_keys(user_id)
password = driver.find_element_by_xpath("//input[@type = 'password']")
password.send_keys(pwd)
driver.find_element_by_xpath("//button[@type = 'submit']").click()
sleep(1)
ztotp = driver.find_element_by_xpath("//input[@type = 'text']")
totp_token = TOTP(totp)
token = totp_token.now()
ztotp.send_keys(token)
driver.find_element_by_xpath("//button[@type = 'submit']").click()
#calling another function
self.stock_1(driver)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment