Selenium Python document.getElementsByClassName()

I’m using Selenium with Python3 to automate entering data into a website. I have tried looking everywhere for how to deal with selecting an element by class if there is more than one but I can’t figure out how to select the accordion-toggle[1]. Nothing happens on selenium but it works fine on any browser. Also, is there any way to just use the regular javascript or jquery commands?:

#otheraccordion=find_element_by_css_selector("#AdvancedAddress > > div.accordion-toggle > span.accordionExpandCollapse")


You are looking for find_element(s)_by_css_selectorreference here – use the css prefix ‘.classname` to indicate the class.

e.g. to find

<div class='theClass'>


You can also use the By syntax:

driver.find_elements(By.CSS_SELECTOR, '.theClass')

It seems the problem may be more to Clicking the element, rather than finding it.

  • Ensure the element is visible
  • For Chrome, you may need to mimic hovering the mouse over the element before clicking this – see Actions / ActionChains MoveToElement to hover over the element.
  • For IE, you may need to ensure the browser / frame gets the focus, prior to the element Click – you may need to apply a hack like one of these.