2

I am on this page: Google Drive Login
Wanting to select this input field:
The input field in question

When I use the xpath of the input field:

//*[@id="identifierId"]

or

/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[1]/div/div[1]/div/div[1]/input

I get nada.

Normally this happens when an element is nested within an iframe but not in this case. Or at least I couldn't find the iframe in question. Please help me understand why.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
AturSams
  • 7,568
  • 18
  • 64
  • 98

2 Answers2

2

The Email or Phone field while accessing Google Drive login page is no different from the Email or Phone field during GMail login.

To send a character sequence to the element you can use either of the following Locator Strategies:

  • Using id:

    driver.find_element_by_id("identifierId").send_keys("AturSams")
    
  • Using css_selector:

    driver.find_element_by_css_selector("input#identifierId").send_keys("AturSams")
    
  • Using xpath:

    driver.find_element_by_xpath("//input[@id='identifierId']").send_keys("AturSams")
    

Ideally, to send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using ID:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "identifierId"))).send_keys("AturSams")
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#identifierId"))).send_keys("AturSams")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='identifierId']"))).send_keys("AturSams")
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome('./chromedriver.exe')
driver.get("https://accounts.google.com/signin/v2/identifier?service=wise&passive=true&continue=http%3A%2F%2Fdrive.google.com%2F%3Futm_source%3Den&utm_medium=button&utm_campaign=web&utm_content=gotodrive&usp=gtd&ltmpl=drive&flowName=GlifWebSignIn&flowEntry=ServiceLogin")
print(driver.title)
time.sleep(7)
search_bar = driver.find_element_by_xpath("//*[@id=\"identifierId\"]")
search_bar.send_keys("some text")

time.sleep(7000)
driver.close()

its working as it is

Output:

enter image description here

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • 2
    Strange :D I did the exact same thing. – AturSams Dec 01 '20 at 12:07
  • @AturSams The unreliable `time.sleep()` does have some impact on the element rendering within the HTML. Hence the difference which you can avoid using [WebDriverWait](https://stackoverflow.com/questions/52603847/how-to-sleep-webdriver-in-python-for-milliseconds/52607451#52607451) – undetected Selenium Dec 01 '20 at 13:07
  • Never use time.slewp always buse explicit wait – PDHide Dec 01 '20 at 13:47