What's the best way to retrieve text from a text input using Selenium WebDriver?

I currently have an HTML element with the following code:

<input id="input-id" type="text" value="initial">
.
Once the page has loaded, I am able to retrieve the text from this element using the command:
driver.find_element_by_id("input-id").get_attribute("value")
.

However, when I click on the element and alter the text inside (for example, changing it to "edited"), nothing in the DOM changes. This includes the value of the value attribute
(i.e.

driver.find_element_by_id("input-id").get_attribute("value")
will still return "initial", and the element in the DOM will appear as
<input id="input-id" type="text" value="initial">
)

How can I retrieve the value that is now visible in the browser (in this case, the string "edited")? Would executing some JavaScript or another method be necessary?

Answer №1

The value remains unchanged after entering new text. You can attempt the following method:

driver.find_element_by_id("input-id").get_attribute("innerHTML")

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

Locating and selecting a boolean checkbox with Selenium and Java: A step-by-step guide

I'm currently attempting to click a primefaces select boolean checkbox using the ID, but I'm encountering an issue. The exception message states: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.id: runDARtest1 I&ap ...

What methods are available for transforming my Python GUI program into a desktop application?

Recently, I created a Python program with a GUI included. Now, I'm looking to turn this program into a desktop app that can be opened without the need for a text editor or command line execution. The program itself searches for and plays the first vid ...

Chaco dynamically updates plot ranges

I am working with a series of dynamically updated chaco plots using a timer object. My goal is to set the Y (referred to as "value" in chaco) limits when the data changes. Upon initializing the plot object, I call: obj.alldata = ArrayPlotData(frequency=f ...

Using BeautifulSoup for extracting data from tables

Seeking to extract table data from the following website: stock = 'ALCAR' page = requests.get(f"https://www.isyatirim.com.tr/tr-tr/analiz/hisse/Sayfalar/sirket-karti.aspx?hisse={stock}") soup = BeautifulSoup(page.content, 'html.pa ...

I'm looking for a simple method to incorporate a legend into my subplots

Just joined this site and excited to share my Python code for plotting vectors, eigenvectors, and their dot product with a matrix. I want to add a legend with colors for each vector/eigenvector on the subplots. Check out the code below: import numpy as n ...

What is the best way to exit the while loop and proceed directly to the finally block when the user inputs the term "done"?

largest = None smallest = None numbers = [] while True: try: user_input = input("Please enter a number: ") except NameError as e: if e == "done": break else: print("Your input is inv ...

Alert: The 'chromedriver' executable file must be located in the PATH directory. For further details, visit the link: https://sites.google.com/a/chromium.org/chromedriver/home

Throughout my experience, I have encountered this question multiple times and found effective solutions. Interestingly, I am able to execute the code flawlessly from the editor (VS Code). However, when I attempt to run it using a batch file (*.bat), an er ...

Exploring the transformation from binary to base 48 representations

A function was recently created to convert binary strings into base48 values. While this function has performed well in most test cases, there is one particular instance where it seems to falter. When the binary string "1010000001101101011000000100000001 ...

Methods for extracting test data from Excel using Selenium

Currently, I am attempting to extract test data from an excel file for use in the sendkeys method. However, upon running my code, I encountered an error at this line: FileInputStream file = new FileInputStream (new File("C:\\Documents and Setting ...

What is the best way to add indentation to HTML code in a code tag?

Looking to insert some Python code into an HTML document using the code tag. Here is an example: <code> for iris, species in zip(irises, classification): if species == 0: print(f'Flower {iris} is Iris-setosa') </ ...

Perform a conditional post-build action in Jenkins without relying on plugins

It seems like I have the ability to make a build step conditional using this interesting plugin: link I'm wondering if this plugin also works for Post-Build steps. Is there a way to make Post-Build steps conditional without relying on a plugin? The ...

Transmission of data through POST method in Hypertext Transfer Protocol

When I send a POST request, how can I retrieve the value associated with the key "success"? Here is what I have tried: @app.route('/register', methods=['GET','POST']) def vid(): if request.method == "POST": firstname=reque ...

I'm facing issues with XPath, even if I directly copied it from Chrome's inspect tool

I've been attempting to automate my tasks and we rely on service-now for our requests. Despite my efforts, I can't seem to get Selenium to function correctly on the service-now website. It works on the login page without any issues, but when it c ...

Errors in Selenium Webdriver - troubleshooting the issues

As I delve into the world of test automation, I decided to try my hand at writing a script using Selenium Webdriver. To my dismay, upon running the script, I encountered a barrage of errors that have left me scratching my head in confusion. Despite metic ...

Performing mathematical operations with Pandas on specific columns based on conditions set by other columns in the dataset

I am working with a Pandas DataFrame import pandas as pd inp = [{'c1':1, 'c2':100}, {'c1':1,'c2':110}, {'c1':1,'c2':120},{'c1':2, 'c2':130}, {'c1':2,'c2':14 ...

Ways to save information to a .csv file chosen by the user using the file_uploader tool in Streamlit

I am currently working on a Web Application using Streamlit and have implemented a file uploader for users to select a CSV file in order to save data. However, I encountered an error while trying to write data from AgGrid to the selected CSV file using the ...

Getting a zero-copy perspective from a C++ raw pointer within pybind11: A step-by-step guide

Kindly review this quick example. sample.cpp #include <pybind11/pybind11.h> #include <pybind11/operators.h> #include <pybind11/numpy.h> namespace py = pybind11; class example { public: example(float val = 1.0f) { data[0] ...

Is it recommended to have a single repository for iOS and Android when creating automation for mobile applications (Native App)?

At the moment, I am utilizing Appium, Selenium, Java, and TestNG for automating a native app. My focus is on iOS and Android platforms, where the functionalities are similar but the element identification process differs between the two. Each element has a ...

Exploring data in Python: Reading CSV files column-wise

I have a python program that needs to manipulate data from a csv file. The file contains rows of varying lengths, like the example below: 1,B,T,P,B,B,B,P,P,P,T,P,P,P,P,T,B,P,P,B,P,P,B,B,P,P 2,T,P,B,P,B,B,P,P,B,B,T,P,B,B,T,P,P,B,B,B,B,P,T,B,T,B,B,B,P 3,P,P ...

Having difficulty establishing a connection between Arduino and Python with the PySerial library

I am currently working on a project with Arduino that involves communication with Python. After researching online, I found a sample code for Arduino Python serial communication which lights up an LED when the number 1 is entered. Although both the Python ...