我有以下循环,但由于某种原因,我无法进入循环内的if语句。我使用计数器来控制循环,但由于某些原因,计数器从不从零开始,似乎以随机数开始。Selenium Webdriver循环控制,无限循环Java
有没有人有任何想法,我的代码有什么问题。
public static void chk_DateAreInRange() throws Exception{
try
{
Date startDate = new Date();
Date endDate = new Date();
int abc = 0;
elementString = driver.findElement(By.id("ctl00_Content_gvList"));
final List<WebElement> dates = elementString.findElements(By.xpath(".//td[1]"));
do
{
for (WebElement date : dates)
{
System.out.println("inside dates for" +abc);
if(abc == 0)
{
System.out.println("inside if x=0");
String[] parsedString = date.getText().toString().split("\\-");// splits the webelement into a string from the - icon
Date ddd = formatter.parse(parsedString[0]);//gets the date we need from string - 12 Nov 2014
String startdateString = formatter.format(ddd);
startDate = formatter.parse(startdateString); // convert the string back into a date
}
if(abc == 99)
{
System.out.println("inside if x=99");
String[] parsedString = date.getText().toString().split("\\-");// splits the webelement into a string from the - icon
Date ddd = formatter.parse(parsedString[0]);//gets the date we need from string - 12 Nov 2014
String startdateString = formatter.format(ddd);
endDate = formatter.parse(startdateString); // convert the string back into a date
}
abc++;
}
}while(abc != 99);
if(getFromDateFull().before(startDate) || getToDateFull().after(endDate)){System.out.println("Date is not in range");}
}catch (Exception e){
Log.error("TOP dropdown is not found on the PLP View Schedule Page");
throw(e);
}
}
控制台输出。
inside dates for349625
inside dates for349626
inside dates for349627
inside dates for349628
inside dates for349629
inside dates for349630
inside dates for349631
inside dates for349632
inside dates for349633
inside dates for349634
inside dates for349635
inside dates for349636
inside dates for349637
inside dates for349638
这与Selenium有什么关系? – SiKing 2014-12-04 15:55:30
没有太多,只是认为id添加它:P – CoffeeTime 2014-12-04 16:55:20