简体   繁体   中英

How to locate kendo button by class using Selenium

I am trying to locate and click a button using Selenium in python. The webpage is kendo based and here is the relevant code for the button:

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

I have tried using this python code:

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

It raises an exception:

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

Can anyone advise on a better method to find the button?

I ended up using the CSS Selector to find it and I had to put a wait in there as well:

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

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