def place_order_via_browser(user_id, password, answer):
"""
Login to the browser and place orders
user_id
user id to log in zerodha
password
password for zerodha
answer
answer to 2FA question. Answers should be same for all
the questions zerodha
"""
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://kite.zerodha.com")
login_form = WebDriverWait(driver, 45).until(
EC.presence_of_element_located((By.CLASS_NAME, "login-form")))
login_form.find_elements_by_tag_name('input')[0].send_keys(user_id)
login_form.find_elements_by_tag_name('input')[1].send_keys(password)
WebDriverWait(driver, 45).until(
EC.presence_of_element_located((By.CLASS_NAME, "button-orange")))
driver.find_element_by_xpath('//button[@type="submit"]').click()
twofa_form = WebDriverWait(driver, 45).until(
EC.presence_of_element_located((By.CLASS_NAME, "twofa-form")))
twofa_form.find_elements_by_tag_name('input')[0].send_keys(answer)
twofa_form.find_elements_by_tag_name('input')[1].send_keys(answer)
WebDriverWait(driver, 45).until(
EC.presence_of_element_located((By.CLASS_NAME, "button-orange")))
driver.find_element_by_xpath('//button[@type="submit"]').click()
time.sleep(2)
driver.quit()