无法使用Selenium处理Kendo Dropdownlist。

huangapple go评论80阅读模式
英文:

Not able to Handle Kendo Dropdownlist using Selenium

问题

我无法选择下拉选项。

示例下拉菜单:https://www.telerik.com/kendo-angular-ui/components/dropdowns/dropdownlist/

我想要从下拉菜单中选择任何内容。

我可以点击下拉菜单,所有菜单都可见,但无法选择任何选项。

我试图找到列表的XPath,但当我点击Kendo-Popup时,它会消失。

英文:

Hi I am not able to select drop-down option..

Sampe Dropdown : https://www.telerik.com/kendo-angular-ui/components/dropdowns/dropdownlist/

I wanted to select anything from dropdown
Image

I am able to click on drop-down and all menus are visible but not able to select any option.

enter image description here

I am trying to find xpath for the list as I click on Kendo-Popupenter image description here

it disappear.

答案1

得分: 1

这个片段可能有帮助:

driver.get("https://www.telerik.com/kendo-angular-ui/components/dropdowns/dropdownlist/")

dropdown = driver.find_element(By.CSS_SELECTOR, "kendo-dropdownlist span.k- 
input")
dropdown.click()

options = WebDriverWait(driver, 
10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "kendo- 
popup ul.k-list li.k-item")))

desired_option = driver.find_element(By.XPATH, "//li[contains(text(), 
'Option 1')]")
desired_option.click()

所以首先点击下拉框以展开它并使选项可见,然后尝试使用适当的定位器(XPath、CSS选择器等)来定位所需选项,这种情况下使用的是CSS选择器,完成后只需点击所需选项以选择它。如果有问题,请告诉我们出了什么问题:D

英文:

this snippet might be helpful:

    driver.get("https://www.telerik.com/kendo-angular-ui/components/dropdowns/dropdownlist/")

    dropdown = driver.find_element(By.CSS_SELECTOR, "kendo-dropdownlist span.k- 
    input")
    dropdown.click()

    options = WebDriverWait(driver, 
    10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "kendo- 
    popup ul.k-list li.k-item")))

    desired_option = driver.find_element(By.XPATH, "//li[contains(text(), 
    'Option 1')]")
    desired_option.click()

so first you click on the dropdown to expand it and make the options visible, try to locate the desired option using an appropriate locator (xpath, CSS selector, etc.), in this case it is cs selector, after doing that just click on the desired option to select it. let us know if that is helpful, if not provide us what went wrong 无法使用Selenium处理Kendo Dropdownlist。

答案2

得分: 0

这不是最佳方法,但它可以正常工作。

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

link = "https://www.telerik.com/kendo-angular-ui/components/dropdowns/dropdownlist/"
driver = selenium.webdriver.Chrome()
driver.get(link)
time.sleep(7)

driver.implicitly_wait(10)
action = ActionChains(driver)
action.scroll_to_element(driver.find_element('id','toc-key-features')).perform()
driver.switch_to.frame(driver.find_element('xpath','//*[@id="gatsby-focus-wrapper"]/main/div[1]/div[2]/article/div[3]/div/div[2]/div/iframe'))
driver.find_element("class name","k-input-value-text").click()
driver.find_element('xpath','//*[text()=\'Chicago\']').click()
time.sleep(2000)
英文:

this is not the best approach but it works fine.

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

link = "https://www.telerik.com/kendo-angular-ui/components/dropdowns/dropdownlist/"
driver = selenium.webdriver.Chrome()  
driver.get(link)
time.sleep(7)

driver.implicitly_wait(10)
action = ActionChains(driver)
action.scroll_to_element(driver.find_element('id','toc-key-features')).perform()
driver.switch_to.frame(driver.find_element('xpath','//*[@id="gatsby-focus-wrapper"]/main/div[1]/div[2]/article/div[3]/div/div[2]/div/iframe'))
driver.find_element("class name","k-input-value-text").click()
driver.find_element('xpath','//*[text()=\'Chicago\']').click()
time.sleep(2000)

huangapple
  • 本文由 发表于 2023年6月1日 22:07:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76382776.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定