Home > Software engineering >  Python/Selenium: Click on button element without ID attribute
Python/Selenium: Click on button element without ID attribute

Time:02-11

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  tabindex="0">Accept All</button>

This is the part of the code:

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.

CodePudding user response:

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()
    
  • Related