简体   繁体   English

如何使用python从硒中的禁用输入中获取文本值?

[英]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.

相关问题 如何使用python从硒的禁用字段中获取文本 - how to get text from disabled field in selenium using python 从Selenium Python中禁用了文本的输入元素中获取文本时出错 - Error getting text from input element with text disabled in Selenium Python 如何使用 Python Selenium 在文本框(输入)中定位并插入一个值? - How to locate and insert a value in a text box (input) using Python Selenium? "使用 python 和 selenium 从 HTML 表中获取特定的文本值" - Get a specific text value from an HTML table using python and selenium 使用Python和Selenium Webdriver从textarea获取文本(无值属性) - Get text from textarea using Python & Selenium Webdriver (no value attribute) 使用 Selenium (Python) 获取输入框的值 - Get value of an input box using Selenium (Python) 如何使用Python使用Selenium Webdriver获取此html中的一些文本值? - How to get the some text value in this html with Selenium Webdriver using Python? 使用python selenium键入文本后如何从搜索建议中获取价值? - How to get value from search suggestions after keying in text using python selenium? 如何获取 Selenium Python 中元素的文本值? - How to get text value of elements in Selenium Python? 如何使用Selenium Python从html表中获取文本对象 - How to get text object from a html table using selenium python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM