Python/Selenium:点击没有id属性的按钮元素

Python/Selenium: Click on button element without ID attribute

嗨,我想点击这个按钮,但我不知道如何找到它,它没有明确的名称或 ID,另外,模拟鼠标点击的代码是什么?

这是HTML:

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

这是代码的一部分:

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

如您所见,send_mouse(Keys.LEFT) 不起作用。

没有send_mouse(Keys.LEFT)

这样的方法

on the element with text as Accept All you can use either of the following

  • 使用css_selector:

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

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