Reputation: 11
How do I access the first element of an array using a CSS selector in python?
For Example:
css=('.od-FieldEditor-fieldTitle.ms-Label.is-required')
returns an array of 6 labels. I want to access the innerText
attribute of the first label.
Image shows the array of labels
Upvotes: 0
Views: 2349
Reputation: 1415
Try this:
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
Upvotes: 1