通过网页列表循环Selenium

时间:2016-10-31 13:56:25

标签: java loops selenium

我在Eclipse中使用Selenium Webdriver。我希望它打开

http://www.sample.com/catalog?product_id="0001"

填写字段并检查径向按钮,然后关闭然后循环打开

http://www.sample.com/catalog?product_id="0002"` 

并执行相同的操作。我希望它循环直到达到9990

System.setProperty("webdriver.firefox.marionette","/Users/Downloads/geckodriver");
WebDriver driver;
driver = new FirefoxDriver();
String base = ("http://www.sample.com/catalog?product_id="0001");   

1 个答案:

答案 0 :(得分:0)

代码段:

for(int i = 1; i <= 9990; i++){
        String base = "http://www.sample.com/catalog?product_id=" + String.format("%04d", i);   
        driver.get(base);
       //do your stuff here
  }

以上代码段将根据您的需要构建您的网址并登陆所需的网页。