1. 程式人生 > >Selenium清空列資料

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(); } } }