【问题标题】:Getting text value of an element with XPATH使用 XPATH 获取元素的文本值
【发布时间】:2022-12-18 09:27:33
【问题描述】:

我想像这样获取页面上所有按钮的文本值:

all_buttons = driver.find_elements(By.TAG_NAME, 'button').getText()

但我得到一个错误:

AttributeError: 'list' object has no attribute 'getText'

如何将按钮的名称提取到列表中?

【问题讨论】:

    标签: python xpath


    【解决方案1】:

    您可以使用list comprehension 获取所有按钮的文本。

    all_buttons = [button.text for button in driver.find_elements(By.TAG_NAME, 'button')]
    

    【讨论】:

      猜你喜欢
      • 2020-03-24
      • 2014-08-09
      • 1970-01-01
      • 2015-11-06
      • 2013-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多