How to select kendo dropdown element with unselectable=“on” attribute using Selenium and Python

前端 未结 1 1961
灰色年华
灰色年华 2020-11-28 17:02

Unable to select the kendo dropdown using below code. The site can be reachable for checking the code.



        
相关标签:
1条回答
  • 2020-11-28 17:42

    To select the item with text as Chang within the kendo dropdown using Selenium you you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      driver.get("https://demos.telerik.com/kendo-ui/dropdownlist/remotedatasource")
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.k-widget.k-dropdown[aria-owns='products_listbox']"))).click()
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.k-animation-container>div#products-list ul li[data-offset-index='1']"))).click()
      
    • Using XPATH:

      driver.get("https://demos.telerik.com/kendo-ui/dropdownlist/remotedatasource")
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='k-widget k-dropdown' and @aria-owns='products_listbox']"))).click()
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='k-animation-container']/div[@id='products-list']//ul//li[text()='Chang']"))).click()
      
    • Note : You have to add the following imports :

      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support import expected_conditions as EC
      

    Browser Snapshot:

    0 讨论(0)
提交回复
热议问题