1

Hi I'm trying to create a script that visits a certain webpage, logs in, navigates to a different subpage, and clicks on an object.

The code below is working fine and well, but there is one problem. It's always waiting for the entire page to load before proceeding. It's like it's ignoring the explicit waits I've assigned, or I don't know what.

Does anyone have any idea what might be happening, and how I can make it proceed as soon as it finds the elements are clickable (what the explicit wait is supposed to do), instead of waiting for the whole page to load?

It's not even throwing a timeout exception, even though I specified the wait time to be 1 second, and it's obviously finding the elements, because the rest of the code proceeds fine, just too slow.

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


driver = webdriver.Chrome('drivers\chromedriver.exe')

wait = WebDriverWait(driver, 1)

driver.get("https://www.webpage.com/login")

ele_email = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@type='email']")))
ele_pass = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@type='password']")))
ele_subm = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@type='submit']")))

ele_email.send_keys("abcd@gmail.com")
time.sleep(2)
ele_pass.send_keys("123456789")
time.sleep(2)
driver.execute_script("arguments[0].scrollIntoView(true);", ele_subm)
ele_subm.click()
time.sleep(5)

driver.get("https://www.webpage.com/subpage")

ele_object = wait.until(EC.element_to_be_clickable((By.ID, "object1")))

driver.execute_script("arguments[0].scrollIntoView(true);", ele_object)
ele_object.click()
fadelm0
  • 263
  • 2
  • 9
  • 1
    @DebanjanB thanks for the pointer, that did the trick! I'm just surprised this wasn't even mentioned anywhere in the various guides for waits online – fadelm0 Jul 21 '19 at 21:16

0 Answers0