Collections:
Disabled Input Field with WebDriver in Python
How to update Disabled input value field value with WebDriver in Python?
✍: FYIcenter.com
Normally, a disabled input value field is used to display some read-only value in the Web page.
The disabled value is not passed back to the Web server when the page is submitted.
You should not change the disabled value.
But if you really want to update the disabled value, you have 2 options:
Here is an example program that uses both options to update disabled values
# UpdateDisabledValue.py
# Copyright (c) FYIcenter.com
from selenium.webdriver import Chrome
driver = Chrome()
driver.get("file:///C:/fyicenter/DisabledValue.html")
# update disabled value directly
input = driver.find_element_by_name("cost")
driver.execute_script("arguments[0].value='9.00';",input)
# make input visible with no value, and enter new value
input = driver.find_element_by_name("margin")
driver.execute_script("arguments[0].disabled=false;",input)
driver.execute_script("arguments[0].value='';",input)
input.send_keys("10.00")
# submit the form
form = driver.find_element_by_tag_name("form")
form.submit()
# check submitted values
print(driver.current_url)
driver.close()
To test the above program, you can use the following HTML file, DisabledValue.html:
<html>
<body>
<p>Form with with hidden values:</p>
<form method="get" action="submit.html">
Cost: $?<input name="cost" type="text" disabled value="10.00"/><br/>
Margin: %?<input name="margin" type="text" disabled value="50.00"/><br/>
Price: $<input name="price" type="text" value="20.00"/><br/>
</form>
</body>
</html>
Run the program:
C:\fyicenter> python UpdateDisabledValue.py file:///C:/fyicenter/submit.html?margin=10.00&price=20.00
The output shows that both options work correctly.
Note that you don't remove the input disabled flag, send_keys() will give you the "selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable" error.
You also need to remove the existing value with "arguments[0].value='';" script. Otherwise, send_keys() will append new value to the old value.
⇒ Selenium IDE - Chrome Extension
⇐ Hidden Input Field with WebDriver in Python
2022-02-02, 7783🔥, 1💬
Popular Posts:
What are JMeter command line options? You can get see JMeter command line options by running this co...
How to perform UUDecode (Unix-to-Unix Decode)? UUEncode is Unix-to-Unix encoding used on Unix system...
How to generate email addresses? To help you to obtain some email addresses for testing purpose, FYI...
How to update hidden input value field value with WebDriver in Python? Normally, a hidden input valu...
Why I am getting gzip compressed HTTP response in SoapUI? If you run a HTTP request for some Website...