如何使用 Selenium 通过 class 定位 kendo 按钮

How to locate kendo button by class using Selenium

我正在尝试在 python 中使用 Selenium 定位并单击按钮。该网页是基于 kendo 的,这里是按钮的相关代码:

<div class="k-header k-grid-toolbar k-grid-top">
   <button class="k-button k-button-icontext k-grid-excel" type="button">

我试过使用这个 python 代码:

driver.find_element_by_class_name("k-button k-button-icontext k-grid-excel").click()

引发异常:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".k-grid-excel"}

谁能建议找到按钮的更好方法?

我最终使用 CSS 选择器找到了它,我也不得不在那里等待:

wait = WebDriverWait(driver, 15)

element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#grid > div.k-header.k-grid-toolbar.k-grid-top '
                                                                      '> button')))
element.click()