How to select kendo dropdown element with unselectable=quot;onquot; attribute using Selenium and Python(如何使用 unselectable=“on选择剑道下拉元素使用 Selenium 和 Python 的属性)
问题描述
无法使用以下代码选择剑道下拉菜单.可以访问该站点以检查代码.
<span unselectable="on" class="k-dropdown-wrap k-state-default"><span unselectable="on" class="k-input">Chang</span><span unselectable="on" class="k-select" aria-label="select"><span class="k-icon ki-arrow-60-down"></span></span></span>代码:从硒导入网络驱动程序从 selenium.webdriver.common.action_chains 导入 ActionChains从 selenium.webdriver.support.select 导入选择从 selenium.webdriver.common.keys 导入密钥进口时间driver = webdriver.Chrome('./chromedriver')driver.get("https://demos.telerik.com/kendo-ui/dropdownlist/remotedatasource")select = driver.find_element_by_xpath('//*[@id="example"]/div/span/span/span[1]')[0]select.SelectByValue("Chang");打印('成功')
使用
Unable to select the kendo dropdown using below code. The site can be reachable for checking the code.
<span unselectable="on" class="k-dropdown-wrap k-state-default"><span unselectable="on" class="k-input">Chang</span><span unselectable="on" class="k-select" aria-label="select"><span class="k-icon k-i-arrow-60-down"></span></span></span>
Code:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome('./chromedriver')
driver.get("https://demos.telerik.com/kendo-ui/dropdownlist/remotedatasource")
select = driver.find_element_by_xpath('//*[@id="example"]/div/span/span/span[1]')[0]
select.SelectByValue("Chang");
print('Success')
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:
这篇关于如何使用 unselectable=“on"选择剑道下拉元素使用 Selenium 和 Python 的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 unselectable=“on"选择剑道下拉元素使
基础教程推荐
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01