简体   繁体   中英

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:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM