Cannot locate form-control object to send_keys using python Selenium

Question:

I am trying to navigate a scheduling website to eventually auto populate a schedule using the following script:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait


# Create a Chrome webdriver
driver = webdriver.Chrome(r'C:Userschromedriver_win32chromedriver.exe')

# Navigate to https://www.qgenda.com/
driver.get('https://www.qgenda.com/')

# Wait for the page to load
driver.implicitly_wait(5) # 5 seconds

# You can now interact with the page using the webdriver
# Locate the sign in button
sign_in_button = driver.find_element(By.XPATH,'/html/body/div[1]/div/header[3]/div/div[3]/div/div/div/div/a')

# Click the sign in button
sign_in_button.click()

# Find the input element
input_email = driver.find_element(By.XPATH,'//*[@id="Input_Email"]')

# Send text 
input_email.send_keys('Josh')

However, I cannot seem to find the Input_Email object. I’ve tried all the Xpaths and Id’s that make sense and also tried waiting until the object is clickable with no luck. Would really appreciate some guidance on this.

I was expecting Selenium to find the html object form box and pass in text but instead I get an error:

NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="Input_Email"]"}
even though the Xpath definitely exists.

Asked By: sdom

||

Answers:

The XPath seems fine. I am guessing you need to do some explicit wait or implicit wait to ensure the page is fully loaded before allocating the element.

Another thing I would like to point out is that given the login URL is available. Locating the sign in button seems to be redundant. You can access it directly via driver.get('https://login.qgenda.com/')

For instance,

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
 
driver.get('https://login.qgenda.com/')
input_email = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, '//*[@id="Input_Email"]'))
)
input_email.send_keys('Josh')

You can read more about it here.

Answered By: Frederickcjo
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.