'How to validate if user is signed in successfully through Gmail account login using Selenium and Python

I'm trying to automate Gmail account login with selenium webdriver, and I need the to check if account signed in successfully and give me the result.

How exactly I can do it?

y = input("input email ID: ")
x = input("input your password: ")            
browser.get('https://accounts.google.com/')
browser.maximize_window()
time.sleep(3)    
User_Id = browser.find_element_by_id("identifierId")
User_Id.send_keys(y)
Next_Button = browser.find_element_by_id('identifierNext').click()
time.sleep(3)
password = browser.find_element_by_name('password')
password.send_keys(x)
time.sleep(2)


Solution 1:[1]

An ideal approach to validate if you have signed in successfully within your account will be to verify the visibility of a visible element.

Once you login through Gmail account login you can verify the visibility of the either of the following elements inducing WebDriverWait for the visibility_of_element_located() and you can use either of the following locator strategies:

  • Verifying the Inbox link:

    WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[contains(@aria-label, 'Inbox') and contains(., 'Inbox')]")))
    
  • Verifying the Primary tab link:

    WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[text()='Primary']")))
    

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 undetected Selenium