Exception Thrown When Selenium Element is Not Visible After Being Triggered in a Specific Area

I'm currently working on automating entries for this giveaway hosted on:

My progress so far includes successfully clicking on the "Visit @nexi_tech on Instagram" link and the subsequent blue button. I then face an issue when trying to interact with the name and email address text boxes displayed here -> Text boxes I'm trying to access

Upon attempting to fill in these details, I encounter the following error message: selenium.common.exceptions.ElementNotInteractableException: Message: Element is not visible

The following snippet of code showcases my second attempt at resolving this issue (with the initial attempt commented out):

# Python 2.7 Code Snippet

from selenium import webdriver
from bs4 import BeautifulSoup
import time
import numpy as np
import pandas as pd

from selenium.common.exceptions import NoSuchElementException

firefox_profile = webdriver.FirefoxProfile()

# Firefox Profile Configurations
firefox_profile.add_extension('/Users/samer/Downloads/quickjava-2.0.6-fx.xpi')
firefox_profile.set_preference("thatoneguydotnet.QuickJava.curVersion", "2.0.6.1")  
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Images", 2)  
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.AnimatedImage", 2)  

# Other Preferences 
# firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.CSS", 2)  
# firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Cookies", 2)
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Flash", 2)  
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Java", 2)  
# firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.JavaScript", 2)  
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Silverlight", 2)  

# Logging In
driver = webdriver.Firefox(firefox_profile)
driver.get("https://gleam.io/jtwmn/3d-printer-giveaway")
driver.maximize_window()

window_before = driver.window_handles[0]

time.sleep(3)
driver.find_element_by_css_selector("a.no-underline.enter-link.instagram-border.clearfix.grey-bg.default").click()
time.sleep(3)

driver.find_element_by_css_selector("a.btn.btn-info.btn-large.btn-embossed.ng-binding").click()
time.sleep(3)

window_after = driver.window_handles[1]

# Switch Windows
driver.switch_to_window(window_after)

# Close new tab after a bit
driver.close()
time.sleep(2)

driver.switch_to_window(window_before)
time.sleep(3)

#Fill In details

driver.find_element_by_xpath('//*[@id="contestant[name]"]').send_keys("John")

# Previous Test
# username = driver.find_element_by_id("contestant[name]")
# emailaddress = driver.find_element_by_id("contestant[email]")

# username.send_keys("John")
# emailaddress.send_keys("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96fcf9fef8d6f1fbf7fffab8f5f9fb">[email protected]</a>")
time.sleep(5)

#Save Details
driver.find_element_by_css_selector("button.btn.btn-primary.ng-scope").click()
time.sleep(5)

print "Save Complete"
driver.quit()
print "Script Ended"

Answer №1

When attempting to find the input element with the id "contestant[name]" using the xpath "//input[@id="contestant[name]", you may notice that it returns a total of 4 elements.

len(driver.find_elements_by_xpath('//input[@id="contestant[name]"))

Out of these 4 elements, only one is visible while the other 3 are not. To interact with the visible input element specifically, you can utilize indexing as shown below:

driver.find_elements_by_xpath('//input[@id="contestant[name]")[3].send_keys("John")

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

Using MongoDB to insert multiple documents in a POST endpoint

When trying to insert multiple documents with MongoDB in the same request, I am encountering an issue where I am getting an undefined value. .post(function (req, res) { ... Item.create(data) .then(function (item) { var newOtherItem; ...

Tips on incorporating .wav audio files into jPlayer

Having issues with .wav audio files in jPlayer. Anyone know how to fix this? Other file formats like audio/mpeg are working fine, but not audio/x-wav. Appreciate any help! ...

If the condition is met with the presence of X in the string, execute one action; otherwise, proceed with

Currently, my code successfully grabs the results: module.exports = async function grabResult(page) { const message = await page.$eval( 'div > div:nth-child(2)', (el) => el.innerText ); const username = await page.$eval( ...

How to implement hover effect to show child div within parent div using React.js

Hey there! I'm fairly new to working with react js and currently trying to add some animation to a nested div. The parent div, known as " portfolio-product-item ", showcases a featured image pulled from the WP REST API. Inside this parent div, there&a ...

Error encountered in Three JS Drag Controls: Unable to assign value to property 'x' as it is undefined

I've been trying to drag the spheres around the scene using drag controls that should be activated when the "m" key is pressed. However, I keep running into an issue where the objects don't move and I receive an error message saying "Uncaught Typ ...

Tips for successfully sending an array via an XMLHttp Get request

I am currently working on a project where I need to utilize all the values from an array in my GET request. The code snippet below outlines my approach: function executeRequest(){ let data = ['value1', 'value2', 'value3'] ...

best method for embedding javascript code within html (within a script tag)

In my quest to create dynamic HTML using jQuery and insert it into a specific div on my website, I encountered an issue. Specifically, I am attempting to generate an anchor element where both the href and label are determined by JavaScript variables. Here ...

Generating a JSON download link using AngularJS

I'm attempting to generate a link that will enable the download of a JSON file in this way Controller $scope.url = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(obj)); View <a href="url" download="download.json">downlo ...

What is the easiest way to connect to MongoDB and add a new post with just a few lines of code?

Currently, I'm working with express.js and node.js. Can you share a brief snippet of code for connecting to mongo and inserting a post into the database? ...

What is the best way to retrieve the full image path in a React component using the `<input>` file element and then save it to the local state?

Creating a basic shopping app using react, react-router, and bootstrap has been an exciting project for me. One of the features in my app is a form where I can add new products to the database. In this form, I can input details such as the product name, d ...

Coordinates in a 3D space following a rotation

I have two specific points, C and P. My goal is to rotate point P around center C in three dimensions. How can I determine the new coordinates of point P after rotation? I am provided with two angles: 'yaw' and 'pitch'. The 'ya ...

What is the best way to access an HTML element when incorporating Vue through a CDN?

In my project, I am utilizing Vue 3.0.2 by loading it through CDN with the following code: <head> ... <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f7818292b7c4d9c7d9c5">[emai ...

Parsing HTML documents for links with Selenium and JUnit

Issue with NullPointerException at if (hrefAttr.contains("?")) An error has surfaced in my project. I'm utilizing selenium and JUnit to navigate through links and cross-reference them with a list of URLs from a CSV file. Everything was working smoot ...

Enable login sessions with Express, Passport, and CORS for various domains

Trying to establish a connection between the frontend (React JS) and backend server (Express JS) has been a challenge due to CORS issues. The requests from the frontend are still being blocked by CORS. Following the guidelines in the CORS documentation, I ...

Ways to define two ng-change functions simultaneously

I am currently working on implementing the phonechange and emailchange functions simultaneously. My goal is to trigger an alert message when both the phone number and email entered are valid. Any assistance from you all would be greatly appreciated! $sc ...

What is the best way to ensure that a JavaScript function is executed continuously for each value in a PHP array?

I am facing a challenge with designing an auction website. My goal is to update the status of specific auctions in a SQL database to 'Closed' once their ending time has passed. However, I'm unsure about how to efficiently run a JavaScript fu ...

Using jQuery to insert PHP code into a <div> element

In our capstone project, I'm looking to implement a dropdown calendar feature. I initially attempted to use ajax within a dropdown Bootstrap 4, but encountered issues with collapsing. As an alternative, I am considering utilizing the include method. A ...

Improving User Experience with HTML Form Currency Field: Automatically Formatting Currency to 2 Decimal Places and Setting Maximum Length

Hello there, I am currently facing an issue with the currency auto-formatting in a deposit field on my form. The formatting adds 2 decimal places (for example, when a user types 2500, the field displays 25.00). However, the script I wrote does not seem to ...

How can you use CakePHP3 to incorporate user notifications in a style similar to Facebook or a stack format through view cells?

When using platforms like Facebook or StackOverflow, we often receive notifications on the top navigation bar without refreshing the webpage. These are known as push notifications. I have a functional CakePHP 3 web app and my client wants to incorporate t ...

Tips on integrating jQuery into html2canvas:

$('#button').on('click', function() { var element = $("#html-content-holder"); // global variable var getCanvas; // global variable html2canvas(element, { onrendered: function(canvas) { getCanvas = canvas; } }); ...