Home > other >  Why am I getting timeout exceptions or cannot find the element errors?
Why am I getting timeout exceptions or cannot find the element errors?

Time:10-08

With this current block of code I am getting a timeout exception error and I am not exactly sure why. Can someone help me fix it? The program currently will get to the correct webpage, it just won't do anything after that. I originally added the wait to help the program in finding the xpath for a text entry box when I was thinking the issue was that the webpage wasn't loading quickly enough. Can someone help me fix this issue so that the program can find the xpath correctly and not timeout?

driver = webdriver.Chrome(executable_path="/Users/username/webdrivers/chromedriver")
driver.get("https://www.vinsolutions.com")

loginButton = driver.find_element("xpath", '//*[@id="top-menu"]/li[6]/a')
loginButton.click()

userNameBox = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, '//*[@id="username"]'))
)
userNameBox.send_keys('username')

CodePudding user response:

you can access the login page directly:

driver = webdriver.Chrome(executable_path="/Users/username/webdrivers/chromedriver")
driver.get("https://apps.vinmanager.com/")

userNameBox = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, '//*[@id="username"]'))
)
userNameBox.send_keys('username')

CodePudding user response:

Your page is loading a little slow after clicking login button you just need to wait around 30 seconds

You can wait for the page to load or wait for the element

userNameBox = WebDriverWait(driver, 30).until(
    EC.presence_of_element_located((By.XPATH, '//*[@id="username"]'))
)
  • Related