Selenium清空列数据

org.openqa.selenium.InvalidElementStateException: invalid element state: Element must be user-editable in order to clear it.

注意:(1)报上边的错误,原因是不是input框,不能进行clear和delete操作,要定位到input

           (2)clear清空数据,value值变为0;要想为空,用delete

rowList.get(i).sendKeys(Keys.chord(Keys.CONTROL, "a"));
rowList.get(i).sendKeys(Keys.DELETE);
public class TestCase  {
    public static void main(String[] args) {
        // 初始化
        WebDriver driver = new ChromeDriver();
        driver.get("http://demo.jeecms.com/jeeadmin/jeecms/index.do#/channel/list");//访问jeecms网站
        driver.findElement(By.xpath("//*[@id="app"]/div/div[1]/div/div[1]/input")).clear();//清除用户名输入框
        driver.findElement(By.xpath("//*[@id="app"]/div/div[1]/div/div[1]/input")).sendKeys("test");//输入用户名
        driver.findElement(By.xpath("//*[@id="app"]/div/div[1]/div/div[2]/input")).clear();//清除秘密输入框
        driver.findElement(By.xpath("//*[@id="app"]/div/div[1]/div/div[2]/input")).sendKeys("test");//输入密码
        driver.findElement(By.xpath("//*[@id="login"]")).click();//点击“登录”
        driver.manage().window().maximize();//放大页面
        driver.findElement(By.xpath("//*[@id="aside"]/ul/li[3]/span")).click();//点击"栏目管理"
        List<WebElement>  roleName=driver.findElements(By.xpath("//*[@id="app"]/div/div[1]/div/section/div[2]/div[2]/div[3]/table/tbody/tr/td[5]/div/div/div/input"));
        for (int i=0;i<roleName.size();i++){
            roleName.get(i).clear();
        }

    }
}

原文地址:https://www.cnblogs.com/xinxin1994/p/10104418.html