我想清除选择类型的下拉菜单中的数据,但我无法使用 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");
我们还可以通过索引或值进行选择 ( documentation )
// finally, to clear your selection, try:
selectElement.deselectAll();
关于java - 如何使用java清除Selenium中的下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39230339/