python selenium checking for element in chrome doesn't work as expected


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 import WebDriverWait
from import expected_conditions as EC
from import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome()
timeout = 10
email = ("[email protected]")

    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!")

For debugging reasons, I’ve been trying this

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from import By
import time

browser = webdriver.Chrome()

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.


Site Isolation is a security feature in Chrome that offers additional protection against some types of security bugs. It uses Chrome’s sandbox to make it harder for untrustworthy websites to access or steal information from your accounts on other websites.

Try opening chrome driver with the following options supplied.

from selenium import webdriver
from import By
from import Service

options = webdriver.ChromeOptions()

chrome_path = r"C:\Users\hpoddar\Desktop\Tools\chromedriver_win32\chromedriver.exe"

s = Service(chrome_path)
driver = webdriver.Chrome(service=s, chrome_options=options)

username = driver.find_element(By.XPATH, '//input[@id="username"]')
username.send_keys('[email protected]')
submit = driver.find_element(By.CSS_SELECTOR, '.ca56ae105.c03eb9739.c026ac3bb.ca0d6234f._button-login-id')
password = driver.find_element(By.XPATH, '//input[@id="password"]')
continueButton = driver.find_element(By.CSS_SELECTOR, '.ca56ae105.c03eb9739.c026ac3bb.ca0d6234f._button-login-password')

Answered By – Himanshu Poddar

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published