当前位置:  开发笔记 > 编程语言 > 正文

为这个庞大的列表制作一个更紧凑的代码

如何解决《为这个庞大的列表制作一个更紧凑的代码》经验,为你挑选了1个好方法。

所以我想让下面的代码更紧凑,有没有办法?

也许有一个循环或什么的.尝试了一个for循环,但没有真正解决这个问题......

        driver.findElement(By.xpath("//input [@value='1']")).click();
        driver.findElement(By.xpath("//input [@value='2']")).click();
        driver.findElement(By.xpath("//input [@value='3']")).click();
        driver.findElement(By.xpath("//input [@value='4']")).click();
        driver.findElement(By.xpath("//input [@value='5']")).click();
        driver.findElement(By.xpath("//input [@value='6']")).click();
        driver.findElement(By.xpath("//input [@value='7']")).click();
        driver.findElement(By.xpath("//input [@value='8']")).click();
        driver.findElement(By.xpath("//input [@value='9']")).click();
        driver.findElement(By.xpath("//input [@value='10']")).click();
        driver.findElement(By.xpath("//input [@value='11']")).click();
        driver.findElement(By.xpath("//input [@value='12']")).click();
        driver.findElement(By.xpath("//input [@value='13']")).click();
        driver.findElement(By.xpath("//input [@value='14']")).click();
        driver.findElement(By.xpath("//input [@value='15']")).click();
        driver.findElement(By.xpath("//input [@value='16']")).click();
        driver.findElement(By.xpath("//input [@value='17']")).click();
        driver.findElement(By.xpath("//input [@value='18']")).click();
        driver.findElement(By.xpath("//input [@value='19']")).click();
        Thread.sleep(1000);
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[1]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[2]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[3]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[4]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[5]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[6]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[7]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[8]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[9]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[10]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[11]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[12]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[13]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[14]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[15]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[16]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[17]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[18]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[19]")).click();
        driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/form/div/div[2]/div[1]/div[2]/div[7]/div/input[20]")).click();

        driver.findElement(By.xpath("//button [@type='submit']")).click();
        Thread.sleep(10000);

这是带有复选框的两个列表.



1> Jan..:

怎么样

    for(int i = 1; i < 20; ++i) {
      driver.findElement(By.xpath("//input [@value='"+i+"']")).click();
    }
    Thread.sleep(1000);

等等其他项目?

推荐阅读
U友50081205_653
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有