Reputation: 2298
I want to get the text from an input element with text disabled.
In the URL below I'm able to write some text to input text box and disable the text but I've tried several ways to get the text in the disabled text box but I'm not sure why is not working.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
url="https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_text_disabled2"
driver_path="/cygdrive/d/d/Python/chromedriver"
driver = webdriver.Chrome(driver_path)
driver.get (url)
driver.set_window_position(0, 0)
driver.set_window_size(1552, 852)
driver.switch_to.frame("iframeResult")
driver.find_element_by_xpath("//*[@id='myText']").send_keys("test123") # write text to input box
driver.find_element_by_css_selector("body > button").click() # Click on button to disable text
I've tried these options even using javascript (that works in Chrome console) but doesn't work with Selenium Python.
driver.execute_script("document.querySelector('#myText').value")
driver.find_element_by_id("myText")).first_selected_option.text
driver.find_element_by_id("myText").getAttribute("value");
>>> driver.find_element_by_id("myText").getAttribute("value")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'WebElement' object has no attribute 'getAttribute'
>>>
Thanks in advane for any help.
Upvotes: 0
Views: 806
Reputation: 716
Python
element.get_attribute("attribute name")
Java
element.getAttribute("attribute name")
Reference: How to get attribute of element from Selenium?
Upvotes: 1