1

I am trying to click a button using Selenium.

Below is the code

<button class="_11f5fc88e3dec7bfec55f7f49d581d78-scss _238c8d0c29802f43d5fb66614d042cfa-scss" title="Play" aria-label="Play" data-testid="play-button" style xpath="1">

I tried to do this by the css selector:

searchButton = browser.find_elements_by_css_selector('[class="_11f5fc88e3dec7bfec55f7f49d581d78-scss _238c8d0c29802f43d5fb66614d042cfa-scss"]').click()

MY ERROR: AttributeError: 'list' object has no attribute 'click'

Am I approaching this wrong? Im not understanding the error.

2
  • That is not a valid CSS selector. To get the CSS selector, right-click on the mouse on the element(<button class) and click copy > copy selector Commented Aug 23, 2020 at 6:55
  • @CarMan does the below answer has solved your issue? if yes, feel free to accept the correct answer with click icon. Commented Aug 24, 2020 at 19:32

2 Answers 2

0

Refer this link of how to use different selectors..
https://selenium-python.readthedocs.io/locating-elements.html

It is recommended to Copy css selector path by inspecting particular element on website then mouse right click -> copy -> copy css path

or by analyzing the code manually enter path

Here p is paragraph tag and class name is content

element = driver.find_element_by_css_selector('p.content')

Sign up to request clarification or add additional context in comments.

Comments

0

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

This error appear because you use .find_elements, it will return a list.

To solve this issue, try this approach:

  1. Using .find_element, without s.
  2. Or still using .find_elements but with index, like this:
browser.find_elements_by_css_selector('[class="_11f5fc88e3dec7bfec55f7f49d581d78-scss _238c8d0c29802f43d5fb66614d042cfa-scss"]')[0].click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.