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.CommentedMar 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-contentCommentedMar 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']") 
2
  • 1
    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.
    – JeffC
    CommentedMar 26, 2019 at 13:44
  • 3
    By request he wanted "all class named = "panel-content""
    – Infern0
    CommentedMar 26, 2019 at 14:10

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.