[英]how to get text value from disabled input in selenium using python?
HTML: HTML:
<input type="text" name="nome" id="nome" class="dez " value="" maxlength="300" disabled="">
Python: Python:
print(driver.find_element_by_xpath("//*[@id='nome']").get_attribute("value"))
It works in enabble input's, but the "nome" input is disable (greyed - not editable).它适用于启用输入,但“nome”输入被禁用(灰色 - 不可编辑)。 So I cant get the text value
所以我无法获得文本值
Can you try the below, I'm just removing the disabled attribute after verifying the visibility of the element and print the text您可以尝试以下操作吗,我只是在验证元素的可见性并打印文本后删除了 disabled 属性
element = WebDriverWait(driver,10).until(EC.visibility_of_element_located(By.XPATH("//[@id='nome']")))
driver.execute_script("arguments[0].removeAttribute('disabled')", element)
print(driver.find_element_by_xpath("//*[@id='nome']").get_attribute("value"))
As I see from HTML you shared this element is not disabled since disabled=""
.正如我从 HTML 中看到的,您共享的这个元素没有被禁用,因为
disabled=""
。
For disabled elements it should be disabled="true"
.对于禁用的元素,它应该是
disabled="true"
。
I guess you are getting empty output for .get_attribute("value"))
here since the element simply have no value
value.我猜你正在为空输出
.get_attribute("value"))
在这里,因为元素根本没有value
的价值。
Someone answered my question so deleted your answer.有人回答了我的问题,所以删除了你的回答。 Thanks anyway, it works: just remove disabled Attribute
无论如何,谢谢,它有效:只需删除禁用的属性
element=driver.find_element_by_xpath("//*[@id='nome']")
driver.execute_script("arguments[0].removeAttribute('disabled')", element)
print(driver.find_element_by_xpath("//*[@id='nome']").get_attribute("value"))
solved解决了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.