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="">
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
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.
CodePudding user response:
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"