I tried below code to fill the login form into www.moneycontrol.com but it seems little bit complicated. Login form is multi-layered,
- hover or click "Hello, Login". click Log-in button inside floating form
- Login with password tab
- then fill email and password to enable login button.
Help is appreciated, code is
from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysimport timeimport pandas as pdfrom io import StringIOfrom bs4 import BeautifulSoupchrome_options = Options()chrome_options.add_argument('--headless')chrome_options.add_argument('--no-sandbox')chrome_options.add_argument('--disable-dev-shm-usage')driver = webdriver.Chrome(options=chrome_options)driver.get('https://www.moneycontrol.com')email = "xxxxxxx@gmail.com"password = "Qxxxxxxx"# Click on the "Login" buttonprint(driver.page_source)login_button = driver.find_element(By.XPATH, '//a[contains(text(), "Hello, Login")]')login_button.click()time.sleep(3) # Wait for login popup to appear# Click on the "Login" buttonlogin_button = driver.find_element(By.XPATH, '//a[contains(text(), "Log-in")]')login_button.click()time.sleep(3) # Wait for login popup to appear# Click on the "Login" buttonlogin_button = driver.find_element(By.XPATH, '//a[contains(text(), "Login with Password")]')login_button.click()time.sleep(3) # Wait for login popup to appear# Switch to login iframe if presenttry: iframe = driver.find_element(By.TAG_NAME, "iframe") driver.switch_to.frame(iframe) time.sleep(2)except: pass # If no iframe, continue normally# Enter email/usernameemail_field = driver.find_element(By.CSS_SELECTOR, '#mc_login > form > div:nth-child(1) > div > input[type=text]')email_field.send_keys(email)# Enter passwordpassword_field = driver.find_element(By.CSS_SELECTOR, '#mc_login > form > div:nth-child(2) > div > input[type=password]')password_field.send_keys(password)# Click on Login buttonsubmit_button = driver.find_element(By.CSS_SELECTOR, '#mc_login button[type="submit"]')submit_button.click()# Wait for login to processtime. Sleep(5)





