I am trying to have the script determine whether an element (in this case the email input space) is present or not. The driver is in the right place as it sends Keys to the right place, but it won't meet the if
condition shown below. I tried to do this with try/except
statement and with a find_elements()
method too. Nothing works. The element is not detected I get a Timeout
error probably because of the expected_condition
statement. The newly opened Chrome tab is a Microsoft Login page if this can help.
My code:
def check_need_to_sign_in():
new_tab = driver.window_handles
driver.switch_to.window(str(new_tab[-1]))
print(driver.current_url)
element_present = EC.presence_of_element_located((By.XPATH, "//input[@class='form-control ltr_override input ext-input text-box ext-text-box']")) # WON'T DETECT ELEMENT):
WebDriverWait(driver, timeout).until(element_present)
if driver.find_elements(By.CSS_SELECTOR, "input.form-control ltr_override input ext-input text-box ext-text-box"): # WON'T DETECT ELEMENT)
print("Element exists")
sign_in()
else:
print("Element does not exist")