[英]Get text from textarea using Python & Selenium Webdriver (no value attribute)
I've looked and tried all i can, i'm in need of assistance. 我已经看过并尽力了,我需要帮助。 I'm trying to get the text from an element in a page.
我正在尝试从页面中的元素获取文本。 Its a popup but not an alert or a new window, just another popup within a frame.
它是一个弹出窗口,而不是警报或新窗口,只是框架中的另一个弹出窗口。 WebDriver appears to find the element, but when i run the print statement to check the text returned, it is consistently a blank line.
WebDriver似乎是在查找元素,但是当我运行print语句检查返回的文本时,它始终是空白行。 I've tried, instead of get_attribute, .text as well... no luck.
我已经尝试过.text而不是get_attribute了……不走运。
Here's the html: 这是html:
<textarea id="textareafield-2320-inputEl" class="x-form-field x-form-text x-form-textarea" name="activityComments" rows="4" cols="20" autocomplete="off" aria-invalid="false" style="width: 100%;"></textarea>
Here's my code: 这是我的代码:
contents = driver.find_element_by_xpath(".//*[@class='x-form-item-input-row']/td[2]/textarea").get_attribute("value")
print contents
Your XPath
is quite broad. 您的
XPath
非常广泛。 Several elements on page might be matched with this XPath
. 页面上的几个元素可能与此
XPath
相匹配。 To check it try print(len(driver.find_elements_by_xpath(".//*[@class='x-form-item-input-row']/td[2]/textarea")))
. 要检查它,请尝试
print(len(driver.find_elements_by_xpath(".//*[@class='x-form-item-input-row']/td[2]/textarea")))
。 If result is more than 1
, you seem to handle wrong element. 如果结果大于
1
,则您似乎处理了错误的元素。
Try to use more explicit XPath
: 尝试使用更明确的
XPath
:
//textarea[starts-with(@id, "textareafield-")][@name="activityComments"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.