简体   繁体   English

使用Python和Selenium Webdriver从textarea获取文本(无值属性)

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

相关问题 如何使用Python使用Selenium Webdriver获取此html中的一些文本值? - How to get the some text value in this html with Selenium Webdriver using Python? 如何使用带有Python的Selenium Webdriver从工具提示中获取没有属性的文本? - How to get text from tooltip with no attributes using Selenium Webdriver with Python? 如何使用 Selenium WebDriver 和 Python 从表中获取元素(文本) - How to get element(text) from a table using Selenium WebDriver with Python 如何使用 selenium python 从下面的 HTML 获取文本属性 - how to get the text attribute from the below HTML using selenium python 使用 Selenium WebDriver 获取文本 - Get Text By Using Selenium WebDriver 使用 selenium webdriver 获取 python 中文本框的 aria-invalid 值 - Get value of aria-invalid of text box in python using selenium webdriver Python Selenium 如果元素中没有文本或值属性,如何获取文本值 - Python Selenium How to get the text value if no text or value attribute in the element 如何使用selenium webdriver python中的span中的定位器打印文本? - How to print the text using a locator from the span in selenium webdriver python? 使用 Selenium webdriver 和 python 验证文本 - 来自元素的 innerHTML - Verify text - innerHTML from element using Selenium webdriver with python 获取属性指定为“的所有标签中包含的文本<div class='wld' text > &quot; 使用 Python 中的 WebDriver Selenium - Get the text contained in all the tag having the attribute specify as "<div class='wld' text >" with the WebDriver Selenium in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM