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

    }
}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM