0

I am on WIN 10 and using Python 3.7. I am trying to login to the below page, but i cannot locate elements:

https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&hl=en-GB

Below is what i tried:

import requests
from selenium import webdriver


driver = webdriver.Firefox()
url_google = "https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&hl=en-GB"
driver.get(url_google)

driver.find_element_by_class_name("Xb9hP").send_keys("1234")
driver.find_element_by_link_text ("Email or phone").send_keys("1234")
driver.find_element_by_css_selector("div.Xb9hP").send_keys("1234")
driver.find_element_by_css_selector("input.email").send_keys("1234")
driver.find_element_by_xpath("//Xb9hP[1]")
driver.find_element_by_xpath("//form[@method='post']")
driver.find_element_by_id("InputEmail").send_keys("1234")
driver.find_element_by_id("InputPassword").send_keys("1111")

Can you please let me know what i shall use? For me to better understand Selenium, i would appreciate examples of how to send "1234" using each function, eg:

find_element_by_id
find_element_by_name
find_element_by_xpath
find_element_by_link_text
find_element_by_partial_link_text
find_element_by_tag_name
find_element_by_class_name
find_element_by_css_selector

Thanks.

cmarios
  • 165
  • 1
  • 10

3 Answers3

2

Avoid using the class name on this field because it seema to be dynamically generated. Please research about Selenium Waits.

1

You can find element by id, and my suggest add WebDriverWait to make sure the element have visible. Try the bellow code :

url_google = "https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&hl=en-GB"
driver.get(url_google)
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, 'identifierId')))
driver.find_element(By.ID, 'identifierId').send_keys('1234')
frianH
  • 7,295
  • 6
  • 20
  • 45
1

using LinkText and ID should work in this case.

driver.find_element_by_link_text ("Email or phone").send_keys("1234")
driver.find_element_by_id("InputPassword").send_keys("1111")

Try using explicit waits for each element.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
# wait for element to appear, then hover it
wait = WebDriverWait(driver, 10)
element = wait.until(ec.visibility_of_element_located(By.Id, "InputPassword"))
Naveen
  • 770
  • 10
  • 22