【问题标题】:Looping through a set of webelements using selenium in python在 python 中使用 selenium 遍历一组 webelements
【发布时间】:2014-06-18 06:14:30
【问题描述】:

我对编码很陌生。我们正在使用 selenium 工具在 python 中编写脚本。

我有以下代码用于单个 Web 元素:

element = driver.find_element_by_css_selector("locator")
           height = element.get_attribute('height')
           print height

现在我的 xpath 表达式返回 8 个项目,我必须为其打印“height”属性。我如何在 python 中做到这一点?

【问题讨论】:

    标签: python loops selenium


    【解决方案1】:

    使用find_elements_by_css_selector():

    for element in driver.find_elements_by_css_selector("locator"):
       height = element.get_attribute('height')
       print height
    

    或者,find_elements_by_xpath(),如果您有 xpath 表达式。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多