英文:
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.
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
答案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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论