![](/img/trans.png)
[英]How to access hidden dropdown menu using Java Selenium webdriver
[英]How to clear a dropdown menu in Selenium with java
我想清除選擇類型的下拉菜單中的數據,但是我不能使用select.clear(),因為它返回錯誤“元素必須是用戶可編輯的才能清除它”,這是很有意義的。 你們中任何人都知道使用什么命令來清除相應的字段嗎?
如果您的元素具有<select>
標記,則可以使用Select類進行交互。
// first, initialize the WebElement (using the appropriate selector type, this is just an example)
WebElement element = driver.findElement(By.id("elementId"));
// next, pass it to the Select object
Select selectElement = new Select(element);
// then, select an option from the element
selectElement.selectByVisibleText("Option Text");
我們還可以通過索引或值( 文檔 )進行選擇
// finally, to clear your selection, try:
selectElement.deselectAll();
如果默認情況下在代碼中選擇了任何選項,則必須使用deselectAll()方法取消選中/清除所有選中的單個/全部下拉/多選選項。
Select DropDown = new Select(driver.findElement(By.id("Drp_ID")));
DropDown.deselectAll();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.