Encountered difficulties while attempting to use keyboard input and received a null value when attempting to retrieve a data-* attribute using Python and Selenium

Encountered an issue with keyboard interaction and finding a null value for the data-* attribute during automated login attempts on Gmail using Python and Selenium

While attempting to automatically log in to Gmail using Python and Selenium, I successfully sent keys to the username field. However, an error occurred when trying to send keys to the password field: raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: Element is not reachable by keyboard

This pertains to the latest versions of Selenium and Python 3

Below is my Python code:

def fill_form():
    driver = webdriver.Firefox()
    #browser initialized
    driver.maximize_window()
    driver.get("https://gmail.google.com")
    driver.implicitly_wait(20) #implicit wait for 20 seconds
    # find username and password element in browser
    print ("-----------------login------------------")
    EMAIL = driver.find_element_by_xpath('//*[@id="identifierId"]')
    EMAIL.send_keys("#my mail")
    next_stepBTN = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/span/span')
    next_stepBTN.click()
    driver.implicitly_wait(20) #implicit wait for 20 seconds
    PASSWORD = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/span/div[1]/div[1]/div/div/div/div/div[1]/div/div[1]/input')
    print("found")
    driver.implicitly_wait(20) #implicit wait for 20 seconds
    PASSWORD.send_keys("#my password") #failed here
    print("send_keys")

In looking for solutions similar to mine, some suggest that using the JS console can help locate elements more accurately. I attempted to locate the password input and change its value in the console. While initially successful in finding the element, it returned null when trying to retrieve the attribute.

var element = document.getElementsByClassName("whsOnd zHQkBf")[0]
element

# result in console below
<input class="whsOnd zHQkBf" type="text" jsname="YPqjbf" autocomplete="off" spellcheck="false" tabindex="0" aria-label="Please enter your password" name="password" autocapitalize="off" dir="ltr" data-initial-dir="ltr" data-initial-value="" badinput="false">

element.getAttribute("data-initial-value")
# Returns null

Although "data-initial-value" changes when entering text in the password field, calling element.getAttribute("data-initial-value") consistently returns null.

I expected the password to be entered automatically via Selenium or JS, but I have tried numerous approaches with no success. Any insights?

Answer №1

It appears that you may be attempting to enter a password before the next page has finished loading, causing an error message when the script tries to input a value into the hidden password field.

https://i.sstatic.net/WYsmD.png

To resolve this issue, consider using the following code with necessary imports:

# Include these imports at the beginning of your script
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

# Implement your logic for entering the username

# Click on the 'Next' button

# Wait for the password field to be displayed
password = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.CSS_SELECTOR,"[name='password']")))
password.send_keys("your password")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS ng-repeat is not updating when the state changes

Seeking assistance with an Angular application challenge I'm facing. I have implemented a ng-repeat in my app to display the latest messages stored in an array within a controller named "comunicacion": ng-repeat in comunicacion.html <div class=" ...

Stop users from refreshing or closing the window while an axios request is being processed

I'm in the process of creating a dynamic Web Application that involves utilizing Axios.get requests. Given that Axios operates asynchronously, my approach includes an async function along with await axios.all: async handleSubmit(){ const ...

Tips on ensuring that the Angular frontend waits for the response from an Express REST call

Upon initializing my user Component, I want to trigger a REST-Call so that the user profile is displayed when the page loads. The process works smoothly as the component communicates with the service, which in turn contacts my express backend to make the n ...

Table header containing the weekdays for a jQuery calendar display

I need some assistance in creating a basic monthly calendar using a table. Check out this demo: www.jsfiddle.net/pzdw0s2n/1/ ...

The function is not recognized in C# programming language

Whenever I try to trigger functions by clicking buttons, nothing seems to happen and an error message appears in the console. Uncaught ReferenceError: AddressInputSet is not defined at HTMLButtonElement.onclick I'm new to this and could use ...

Loop through each HTML element and store it in a JavaScript array

I currently have a webpage with 3 select buttons named "Season". I am trying to figure out which buttons are selected and receive their values as an array on my webpage. Below is the code I am using: var season_array = $.each($(form).children("input.sele ...

Steps to altering the color of a second button with a button click

My goal is to create a button click function that allows only one button to be clicked at a time. For instance, when btn1 is clicked, its background color changes from transparent to green. Then, if btn2 is clicked, btn1's background color should chan ...

React - Obtain User Login Details and Verify

I am working on a React project that includes a Login Form. The code has been organized into small components for reusability, but I am unsure of how to retrieve and validate user credentials (username and password). Is there a method available to validate ...

How can async/await help in retrieving the value of a CORS request?

Trying to make a CORS request and utilize async/await to extract the value from it (using jquery). The functions createCORSRequest and executeCORSRequest seem to be functioning correctly, so the implementation details are not my main concern. The function ...

An issue has been encountered within the for loop, specifically relating to an error regarding

Currently, I am working on a program that scans a string to find instances of 'bob' and then displays the number of times it occurs. Take a look at my code snippet: s = 'mbobobboobooboo' numbob = 0 for i in range(len(s) ) : u = s[i ...

What steps can be taken to safeguard data while navigating within the Angular framework?

I am facing an issue with storing an array of items in a service (referred to as cart service) and displaying it in the component (cart.component.ts). The components bgview.component.ts and single.component.ts are involved in selecting individual items, wi ...

Tips for choosing a specific cell in a table

I currently have a total of 14 cells that have been generated. Is there a way for me to individually select and manipulate a specific cell out of the 14? I am looking to make only one cell unique, while leaving the rest to be displayed as they are in the ...

What steps can I take to stop my browser from displaying the "waiting for MyHostName" message while performing an ajax Post/Get operation?

Whenever I access a website using Chrome, a message appears in the status bar saying "Waiting for MyHost name" along with an Ajax Loader circle in the browser tab. Here is a javascript function that I am working with: function listen_backend_client_reques ...

Determining height of an element in AngularJS directive prior to rendering the view

As I dive into the world of Angular, any assistance is greatly welcomed. My goal is to vertically align a div based on screen size (excluding the header and footer) when the page loads, the window resizes, and during a custom event triggered by the user ex ...

When altering the color of a mesh in Three.js, only a single face is impacted by the modification

I have a GLB model with multiple parts and hierarchy. My goal is to highlight a specific part of the assembly on mouseover. The code snippet I am using for this functionality is as follows: raycaster.setFromCamera( pointer, camera ); ...

Express displays HTML code as plain text

I am currently facing an issue where I am trying to display an html table on /guestbook.ejs and then redirect it to /guestbook. However, the content of my guestbook.ejs file is being displayed as plain text rather than rendering the HTML code. Below is th ...

The Angular web application utilizing an ASP.NET Web API that is hosted on AppHarbor is showing the incorrect webpage

Working on a web application using Angular and ASP.NET Web API in Visual Studio 2015 has been quite the journey for me. Upon running the solution in VS2015, I encountered two tabs opening in Chrome - one for my Angular client-side application and another ...

The excessive use of Selenium Webdriver for loops results in multiple browser windows being opened simultaneously, without allowing sufficient time for the

Is there a way to modify this code so that it doesn't open 150 browsers to google.com simultaneously? How can I make the loop wait until one browser finishes before opening another instance of google? const { Builder, By, Key, until } = require(& ...

If a different link is selected, remove the class from the ID, and vice versa

I've been working on solving a jQuery issue that involves manipulating classes in a parent container with two divs and links. The goal is to add a class to change the background when a link is clicked in one div, and remove it if the other link is cli ...

What might be causing the status problem to not display correctly?

My toggle feature to switch between no issue and issue is not displaying the status correctly. Despite trying to troubleshoot, I can't figure out why the issue section is not showing up. <!DOCTYPE html> <html> <script src="https://aj ...