XPATH did not locate any elements in the document

Trying to extract specific text from an element within a table using the XPATH below:

/html/body/form[2]/table/tbody/tr/td/table/tbody/tr[2]/td[7]/input

attempting to do so with the following code:

driver.maximize_window() # Maximize window
driver.implicitly_wait(3) # Set implicit wait for 20 seconds
driver.find_element(By.XPATH, value = "/html/body/form[2]/table/tbody/tr/td/table/tbody/tr[2]/td[7]/input").text()

unfortunately encountering the error message:

NoSuchElementException: Message: Unable to locate element: /html/body/form[2]/table/tbody/tr/td/table/tbody/tr[2]/td[7]/input

Attempted accessing the element via CSS selector and value without success. Cannot provide the link due to security restrictions, but here is a screenshot of the element

https://i.stack.imgur.com/8PuXV.png

Answer №1

Consider using a relative XPath instead of an absolute one. Here is the expression:

//input[@name='AdjIncrementAmount_1']

It's uncertain from the screenshot whether the attribute name (after the text Amount) contains a single _ or double __. If the first option doesn't work, give the second one a try:

//input[@name='AdjIncrementAmount__1']

Answer №2

If you need to display the text $36,400.00 on your webpage, you have two options for using locator strategies. Check out this link for more information:

  • For css_selector:

    print(driver.find_element(By.CSS_SELECTOR, "td > input[name='AdjIncrementAmount__1']").get_attribute("value"))
    
  • Or for xpath:

    print(driver.find_element(By.XPATH, "//td/input[@name='AdjIncrementAmount__1']").get_attribute("value"))
    
  • Please note: Don't forget to include these imports :

    from selenium.webdriver.common.by import By
    

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

Python encountered a ValueError due to an embedded null character while trying to Import a JSON file

I'm encountering an issue while attempting to import a JSON file into Python. with open('e:\0_1export.json', 'r') as f: data = f.read().strip(); Error message: ValueError Traceback (most rece ...

Clicking the radio button automatically triggers its click() method, causing it to toggle between being clicked and un

I encountered an issue while attempting to trigger the click event of a radio button using the click() method in Selenium WebDriver. Even though the element is successfully identified and clicked, it quickly becomes unselected due to the click being perfor ...

Encountering an issue with Python: "IndexError: list index out of range"

I can't figure out what I did wrong. names = ["paris capital", "london capital", "berlin capital"] for i in range(0,3): city = names[i+1] print(city) Mistake: File "C:\Users\Utilisateur\PycharmProjects\myfirstproject&bso ...

Selenium Python is having trouble finding the element

While utilizing Selenium in Python, I encountered a challenge with inputting information into the expiration date and CVV fields. These fields are located within iframes, and although I successfully entered the credit card number, the other fields remained ...

Why is the upload handler not aligning with GAE Blobstore?

Following the documentation provided by GAE, I have implemented an upload handler to upload blobstore. However, when I select a file on my computer and click the Submit button on the HTML page, it displays 'The url "/upload" does not match any handler ...

What is the process for recursively extracting specific fields from json data?

Underneath is a sample json document or json variable that I'm working with in python to extract specific fields. Any guidance on how to accomplish this task would be greatly appreciated. json_variable = { "server01":{ "addr ...

Struggling to Locate Elements by Xpath or Text Using Selenium Webdriverjs

After finding a few more issues to address, I am back to where I left off yesterday. My challenge now is to locate these elements using only text. Eventually, all will be updated to utilize ids. When I analyze the element in FirePath, the xpath is quite m ...

Learn how to effortlessly update models by integrating AngularJS with Django and Django Rest Framework

Here is a JSON representation of a post based on its ID: http://127.0.0.1:8000/update/1?format=json {"title": "about me", "content": "I like program", "created": "2014-11-29T18:07:18.173Z", "rating": 1, "id": 1} I am attempting to update the rating ...

The WebDriver appears to be using a null Session ID from Selenium, possibly due to calling quit() before continuing with another test. This

When trying to run a test in Selenium with Junit, I encountered an issue. The test executes but I receive the following failure message - 1) testTripPlannerJUnit(com.example.tests.TripPlannerJUnit) org.openqa.selenium.NoSuchSessionException: Session ID ...

Reshaping Images using PyTorch

My image has dimensions (32, 3, 32, 32), following the format (batch_size, Channel, Height, Width). I am looking to convert it into (32, 32, 32) by disregarding the Channel. How can I achieve this transformation? ...

During the transfer of data from Sybase to MySQL, an issue arose with the Python module function DbSQLAnywhereRE.reverseEngineer

I'm currently in the process of transferring a database from Sybase to MySQL using the migration tool provided by MySQL Workbench. Although I have successfully established connections between the data source and target database, I encounter an error ...

What are the steps for utilizing importlib?

Currently, I am in the process of transitioning some code to an Azure function while still needing it to function as a service fabric app temporarily. The Python code is located within a directory named "DocClassify.Api", which has a period in its name mak ...

Issue with the lxml version - encountering difficulty in invoking the findall method!

An error occurs in lxml version 1.3 for the following line of code: self.doc.findall('.//field[@on_change]') File "/home/.../code_generator/xmlGenerator.py", line 158, in processOnChange onchangeNodes = self.doc.findall('.//field[@on_chan ...

Challenges associated with parsing JSON structures that have nested lists and dictionaries

I'm currently in the process of writing a script that will generate a CSV file based on parsed JSON data. While I have successfully managed to read the JSON, I've hit a roadblock with a TypeError: list indices must be integers, not dict. Previou ...

Show today's date in Python using the mm/dd/yyyy layout

import datetime current_time = datetime.datetime.now() print(f"{current_time.month}-{current_time.day}-{current_time.year}") #Will print the current date in a mm/dd/yyyy format. input() The code above is designed to display the current date in a mm/dd/y ...

Remaining authenticated with Selenium through Python

While using Selenium, I am facing an issue where I log into a website successfully but when I try to navigate to another page on the same site, I find that I have been logged out. I suspect this is due to my lack of understanding about how the webdriver.F ...

Looking for assistance in consolidating identical values in a dictionary into one cohesive group

I am working with a json file that has specific data formatting. { "courses": [ { "professors": [ { "first_name": "Zvezdelina", "last_name": "Stankova", "p ...

Updating the system PATH in the Windows Registry using Python's winreg module

Currently, I have developed a program that is designed to add directories to the PATH variable through the registry. The selection between the HKCU (user) or HKLM (system) path is dependent on an input option. The program functions correctly when utilizin ...

What are the advantages of using Selenium Edgedriver's Send Keys to select all and copy text?

Being a novice to using Selenium, I'm exploring this auxiliary library for the first time in VBA. I've opted to use the Web Driver for Microsoft Edge, and I'm encountering challenges with implementing send keys. Specifically, I am trying to ...

Encountering the "Element not clickable" problem with Selenium

Unable to interact with the element. The test runs smoothly on a computer, but fails when run on a laptop displaying error message 'Element not clickable'. Attempted various wait times without success. Uncertain of the root cause. My current appr ...