Selenium and Python: Dealing with the ElementNotInteractableException when trying to input a value in a td element

My attempt to input the number 1 into the MasterPack boxes in this table is met with an error indicating that it is not interactable. https://i.sstatic.net/J79p6.png

I encountered the "element not interactable" error while using the following code:

driver.find_element_by_xpath('//*[@id="asnPick_order_0_itemInfo_TABLE"]/div[1]/div/div/div/table/tbody/tr[1]/td[8]')
.send_keys("1")

The table's HTML shows that I am targeting the MasterPack cell, which is blank and lacks any attributes. The other cells' text is not attribute-based but simply nested within the tags.

<tr><td class="">0001</td>
<td class="">1022-0221-00</td>
... (remaining HTML content)

Although clicking on the MasterPack box seems successful, sending keys triggers the interactability issue. Is there a way to edit the numbers in untagged cells like these without encountering errors?

Additional investigation led me to uncover a temporary workaround:

driver.find_element_by_xpath('//*[@id="asnPick_order_0_itemInfo_TABLE"]/div[1]/div/div/div/table/tbody/tr[1]/td[8]').click()
element = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, "//table[@class='htCore']//tbody/tr//td[contains(@class, 'highlight')]")))
driver.execute_script('arguments[0].innerHTML = "1"', element)

While this successfully inputs the number one, it disappears upon saving the page. It appears that only the visual aspect of the form is being altered, resulting in a transient change. Any suggestions on how to make this change permanent or securely modify/send keys to the HTML? Thank you.

Here is the HTML snippet after adding the number 1:

<td class="current highlight">1</td>

Answer №1

If you want to assign the value of 1 to the MasterPack column in the first row, you can achieve this using a specific based Locator Strategy:

  • One method is to use setAttribute():

    element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//table[@class='htCore']//tbody/tr//td[contains(@class, 'highlight')]")))
    driver.execute_script("arguments[0].setAttribute('value','1')", element)
    
  • Another option is to utilize setValue():

    element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//table[@class='htCore']//tbody/tr//td[contains(@class, 'highlight')]")))
    driver.execute_script("arguments[0].value='1';", element)
    

For further information, check out these resources:

You may find additional insights from these discussions:

  • Utilizing JavascriptExecutor for Selenium Datepicker
  • Troubleshooting "Send keys not working" issue in Selenium WebDriver using Python

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

Tips for utilizing the 'contains' feature within web elements with Java Selenium WebDriver?

In my current project, I am facing a challenge with two specific elements: one is a string formatted as ABC £12,56 and the other is a box called "Cashbox" that should be 15% of the value of the string. However, when attempting to locate the CSS for both e ...

Ever since updating my jQuery version to 3.2.1, my ajax code seems to have stopped functioning properly

My program's ajax functionality was running smoothly with jquery version 1.7, but when I updated to version 3.3.1, the ajax part stopped working. I made sure to attach the ajax portion of my code after updating the jQuery version. In the PHP file, I s ...

Creating a Nested DataTable: A Step-by-Step Guide

My data structure includes a nested dict presented as follows: var dataSet = [{"s_group": [{"range_name": null, "name": "XXXXXXXXXXXX"}], "configfile": "XXXXXXXXXXX", "src_port": ["0-65535"], ...

What is the best method to invoke a function recursively with a delay of 1 second following the completion of an ajax

I am facing a situation where I need to implement a delay of 1 second after an ajax request is completed, regardless of the outcome. Instead of calling a method every second, I specifically want to call a function 1 second after the ajax request finishes. ...

Minimize the length of the styled-component class name in the upcoming iteration

Dealing with styled-components in Next along with React can pose a challenge when it comes to ensuring proper rendering of the styled components. To tackle this issue, Next offers the compiler.styledComponents flag within the next.config.js file like so: c ...

Access user connections through Discord.js bot

Hi there, I'm currently working on creating a bot that can retrieve a user's connected battle.net account and display their game rank. I am utilizing the discord.js library and have been attempting to access the UserProfile through the bot. Unfor ...

Validating properties of a class using Typescript's Class-Validator

I tried using the class-validator decorator library for validation processes on my sample project. However, it doesn't seem to be working as expected. The sample project aims to create projects based on user inputs, and I'm attempting to validate ...

Enhance the php query limit using javascript when loading additional content

Hey there, currently working on implementing a reverse infinite scroll feature for a private messaging module. Everything seems to be functioning well, except for one issue I'm facing - struggling to update the query limit. I set the maximum and lim ...

Drawing intersecting lines on a javascript canvas and clearing them using the lineto method

I am working with a canvas where lines are drawn based on mouse movement. I am trying to achieve the effect of the line only lasting for a few seconds before disappearing, similar to swirling a ribbon with a set length. I have been using lineTo to draw the ...

You will encounter a TypeError with the message "Super expression must be null or a function" when attempting to export a named class

I'm experimenting with components. I have a default export in place but now I think I need to create a named class for my next export. Take a look at the code below: export default Users; import React from 'react'; export class UsersTest e ...

Is it possible to utilize a Python Selenium dictionary to create a more generalized xpath for a locator class

Is it feasible to consolidate multiple XPaths into a single 'general XPath' using a Python dictionary? In a locators class, I aim to identify all elements in a formula for automated data input (in the context of testing automation). For each fiel ...

JavaScript Event Listener causing the Sticky Position to Break

I am currently dealing with a situation where I want to create a slide-in side menu that remains sticky. However, when I apply the position: sticky CSS property to my menu container, it causes the entire menu to be displayed (instead of being pushed off th ...

What is the best way to create a slideshow using an IFrame?

Currently seeking a solution for an iframe slideshow that can smoothly transition between multiple HTML iframes. I have a total of 5 iframes that need to rotate automatically and continuously. Any suggestions on how to build a lively and dynamic iframe sl ...

Link components in Next.js now automatically add the current path when working with nested dynamic routes, making it

How can I effectively handle nested dynamic routes and utilize the Next.js Link component? Let's say I have 2 different file paths: /pages/projects/index.js <Link href={`/projects/${project.id}`} key={index}> <a>Project Name</a> ...

Issue with querying and ordering products in Django using Python when passing values through the GET request

I have been working on a project where I need to filter products and sort them by price in ascending and descending order. Here is the code snippet from my view: def is_valid_queryparam(param): return param != '' and param is not None def f ...

Why do I keep encountering a null window object issue while using my iPhone?

Hey there! I've got a React game and whenever the user loses, a new window pops up. const lossWindow = window.open( "", "", "width=500, height=300, top=200, left = 200" ); lossWindow.document.write( & ...

How can you verify the correctness of imports in Typescript?

Is there a way to ensure the validity and usage of all imports during the build or linting phase in a Typescript based project? validity (checking for paths that lead to non-existent files) usage (detecting any unused imports) We recently encountered an ...

Exploring the power of regular expressions in Javascript when used between

Consider the scenario outlined in the text below I desire [this]. I also desire [this]. I do not desire \[this] I am interested in extracting the content enclosed within [], but not including \[]. How should I approach this? Currently, I have ...

how to navigate to different windows in Selenium WebDriver

Every time I click the login button, a new window (not tab) opens and I am trying to switch to the newly opened window. Here is my code, but it's not working properly as the driver is not switching to the other window. System.setProperty("webdriver.c ...

transfer properties to a dynamic sub element

I am currently working on a multi-step form project. I have successfully implemented the form so that each step displays the corresponding form dynamically. However, I am facing challenges in passing props to these components in order to preserve the state ...