Home > Mobile >  Selenium Python - How to find elements in a dynamic website (getting NoSuchElementException exceptio
Selenium Python - How to find elements in a dynamic website (getting NoSuchElementException exceptio

Time:10-18

I am trying to automate login for the website as shown here.

Now, I try to perform inspect element for 'email' and 'password' but I keep on getting the NoSuchElementException exception. For eg., 'Inspect Element' on email shows an HTML input tag with 'emailid' as the ID. So I tried the following

inputElement = driver.find_element_by_id('emailid')
inputElement.send_keys(email)

But as said earlier, this gives NoSuchElementException exception. Similar issues with password and other options. Kindly help me with it.

CodePudding user response:

You just have to place a webdriverwait which will wait for the element to be loaded. This should work:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome("D:/chromedriver/94/chromedriver.exe")
driver.get("https://www.crisilresearch.com/#/")
# wait 60 seconds 
wait = WebDriverWait(driver,60)


wait.until(EC.element_to_be_clickable((By.XPATH, '//a[text()="Login "]'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@id="emailid"]'))).send_keys("[email protected]")
wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@id="passwords"]'))).send_keys("myPassw0rd")
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@id="sub"]'))).click()
  • Related