How to copy the text of an input, which is not in the html code with selenium Python

I have a problem with a input, because its value do not store in html code.

This is the html code

<input spellcheck="false" class="editablesection" onkeypress="checkKey(event)" oninput="writinginput(this, 0)" maxlength="11" style="width: 113px;" readonly="">

Image of input with text

I search the element with this:

input = driver.find_element_by_css_selector(".editablesection")

But i cant copy the text because its not store in html code.

How i can do it?

Site where input its located: https://www.w3schools.com/html/exercise.asp?filename=exercise_html_tables6

You need to click "Show Answer" button to see the text i want to copy.

Upvotes: 1

Views: 368

Answers (1)

QualityMatters
QualityMatters

Reputation: 915

You can use selenium get_attribute("value") method to extract the value. Below is the code from selenium python:

driver = webdriver.Chrome(PATH)

driver.get('https://www.w3schools.com/html/exercise.asp?filename=exercise_html_tables6')
driver.maximize_window()
sleep(3)
driver.find_element(By.XPATH,"//button[contains(.,'Show Answer')]").click()
sleep(3)
readOnlyField = driver.find_element(By.CSS_SELECTOR,"#showcorrectanswercontainer > .editablesection")
print(readOnlyField.get_attribute("value"))
driver.quit()

Output:

rowspan="2"

Upvotes: 3

Related Questions