This works just fine in Firefox. When I use Chrome, once the page fully loads it doesn't print "element loaded", and it doesn't go to timeout either. It just waits forever.
I've tried using visibility_of_element_located
instead of presence_of_element_located
but it makes no difference. I've tried all_elements
too. Any advice?
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome()
browser.get("http://url.com")
timeout = 10
email = ("email@gmail.com")
try:
email_form_wait = WebDriverWait(browser, timeout).until(EC.presence_of_element_located((By.XPATH, '//*[@id="username"]')))
print ("element loaded")
email_form = browser.find_element(By.XPATH, '//*[@id="username"]')
email_form.send_keys(email, Keys.ENTER)
except TimeoutException:
print ("Loading took too much time!")
Update For debugging reasons, I've been trying this
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
browser = webdriver.Chrome()
browser.get("http://url.com")
time.sleep(5)
print("end wait")
This works as expected on Chrome, but when I add
email_form = browser.find_element(By.XPATH, '//*[@id="username"]')
print("element found")
at the end of the code, it doesn't even print "end wait", it's stuck waiting forever and then it prints "end wait" and returns an error only after I force close the browser.