【问题标题】:How to get length of text box from webpage in python如何从python中的网页获取文本框的长度
【发布时间】:2015-12-07 11:39:23
【问题描述】:

如何从文本框中获取文本,从网页中获取搜索框。我正在尝试获取文本并获取长度以检查它是否为空。 例如

 driver = webdriver.Chrome()
 driver.get('http://www.yahoo.com')

我尝试了driver.find_element_by_name('p').text,但即使有文本,它也会打印出 null。

【问题讨论】:

  • 请提供更多信息。我不知道你是用 Python 还是 JS 编写,因为你有两个标签。
  • 我正在用 python..edited 编写

标签: python html selenium selenium-webdriver webpage


【解决方案1】:

对于input 网络元素使用el.get_attribute('value')

In [14]: driver = webdriver.Chrome()

In [15]: driver.get('http://www.yahoo.com')

In [16]: search = driver.find_element_by_css_selector('input[title=Search]')

In [17]: search.get_attribute('value')
Out[17]: u''

In [18]: search.send_keys('SO the best!')

In [19]: search.get_attribute('value')
Out[19]: u'SO the best!'

【讨论】:

    猜你喜欢
    • 2020-03-25
    • 2020-07-27
    • 1970-01-01
    • 2019-11-29
    • 2011-09-26
    • 2019-06-27
    • 2010-09-09
    • 1970-01-01
    • 2020-05-14
    相关资源
    最近更新 更多