Reputation: 59
I'm trying to locate an element in a form, but for some reason Selenium keeps throwing an error saying it can't be found. Here is the simple code that I'm using. Can anyone decipher why this isn't working? It looks like a basic HTML form.
driver = uc.Chrome()
driver.get('https://www.stumblechat.com/register')
username = driver.find_element(By.ID, 'user')
Upvotes: 1
Views: 146
Reputation: 33361
There are 2 problems here:
WebDriverWait
expected_conditions
explicit waits.input[name='username']
.from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)
url = "https://stumblechat.com/register"
driver.get(url)
username = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='username']")))
Upvotes: 1