Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python/Selenium: Click on button element without ID attribute

Hi I want to click on this button but I don’t know how to find it, it has no explicit NAME or ID, also, what is the code to simulate a mouse click?

This is the HTML:

<button class="aOOlW  bIiDR  " tabindex="0">Accept All</button>

This is the part of the code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

auth = driver.find_element(By.CLASS_NAME, 'aOOlW  bIiDR  ')
auth.send_mouse(Keys.LEFT)

As you can see send_mouse(Keys.LEFT) doesn’t work.

>Solution :

There is no such method as send_mouse(Keys.LEFT)


To click() on the element with text as Accept All you can use either of the following locator strategies:

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "button[tabindex='0']").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//button[text()='Accept All']").click()
    
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading