I'm trying to set text to the following text box-
<input type="text" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="off" spellcheck="false" tabindex="0" aria-label="First name" name="firstName" value="" autocapitalize="sentences" id="firstName" data-initial-value="" badinput="false">
By using the following python code-
import time
import pandas as pd
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
exe_path = '/usr/local/bin/chromedriver'
driver = webdriver.Chrome(exe_path)
driver.implicitly_wait(10)
driver.get('https://support.google.com/mail/answer/56256?hl=en')
driver.find_element_by_class_name('action-button').click()
f = driver.find_element_by_id('firstName').send_keys('hfsjdkhf')
It does find the element and the but the cursor just stays there a while and I get the following error-
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="firstName"]"}
(Session info: chrome=80.0.3987.132)
How do I fix this??
driver.find_element_by_id('firstName')looks fine. So please try to wait for the presence of element before callingsend_keysaction-button, which opens a new tab, selenium continues reading on the old tab, as you can see by usingprint(driver.current_url), please check solution below.