【问题标题】:Python - Selenium (find elements by CSS selector)Python - Selenium(通过 CSS 选择器查找元素)
【发布时间】:2017-08-23 15:10:48
【问题描述】:

如何在 python 中使用 CSS 选择器访问数组的第一个元素?

例如:

css=('.od-FieldEditor-fieldTitle.ms-Label.is-required') 返回一个包含 6 个标签的数组。我想访问第一个标签的innerText 属性。

Image shows the array of labels

【问题讨论】:

    标签: python css selenium


    【解决方案1】:

    试试这个:

    elements = driver.find_elements_by_css_selector('selector_required')
    
    
    # if you want to navigate through
    for e in elements:
        # do some stuffs with 'e'
    
    # to access a single object
    e = elements[0] # will return the first element of a list
    

    【讨论】:

      猜你喜欢
      • 2021-11-21
      • 2023-03-16
      • 2018-10-22
      • 2019-04-30
      • 2020-10-30
      • 2015-10-15
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多