3

I want to get all class named = "panel-content" only, so i have done this:

driver.find_elements_by_css_selector("div.panel-content")

but it also selects the class named = "accordion-table panel-content", as it has "panel-content" string in it's name. but what i want is only "panel-content" class.how to do that?

2
  • Can you show us what the html looks like? You'll have to find a unique selector. In the firefox devtools you can right-click -> copy -> css selector to copy the exact css selector for an element, maybe this helps. Commented Mar 26, 2019 at 12:49
  • Can you explain that further? If some element has the raw class string accordion-table panel-content, that means that this element has both the class accordion-table and panel-content Commented Mar 26, 2019 at 12:55

1 Answer 1

2

https://www.w3schools.com/cssref/css_selectors.asp

Here you go:

CSS selector:

[class='panel-content']

Locator:

driver.find_elements_by_css_selector("[class='panel-content']")
Sign up to request clarification or add additional context in comments.

2 Comments

This is not a good way or a CSS-like way to do this. You have basically reduced the class name check to a string match. If any other class gets added to this element, this will fail.
By request he wanted "all class named = "panel-content""

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.