Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

How to store webelements(dates) in an array and retrieve it?

I got the total no. of dates by using the xpath :

  • //div[@class='datepicker']/div/table/tbody/tr/td/table/tbody[2]/tr/td[@class='' or @class='datepickerSaturday' or @class='datepickerSunday']/a/span[contains(text(), '')]"));

Consider the no. of dates is 23. Store these dates in array and iterate them. Get the first value, and it should be placed like

  • //div[@class='datepicker']/div/table/tbody/tr/td/table/tbody[2]/tr/td[@class='' or @class='datepickerSaturday' or @class='datepickerSunday']/a/span[contains(text(), 'FIRSTVALUE')]")).click;

I tried the below code.

 List<WebElement> allLinks= ss.findElements(By.xpath("//div[@class='datepicker']/div/table/tbody/tr/td/table/tbody[2]/tr/td[@class='' or @class='datepickerSaturday' or @class='datepickerSunday']/a/span"));
 //display the count of links in the page
 // display the text for each link on the page
 for( int i=0; i<=allLinks.size(); i++)
    //display text for each link
    //perform click action
    //code for booking appts                                   
    slots2 = ss.findElements(By.xpath("//div[@class='time_sheet']/ul[@class='morning' or 'afternoon' or 'evening']/li/a")).size();
    System.out.println("No of available slots" +slots2);
    int count2=slots2;
    for(int j=0;j<=count2;j++)
          // code to execute

On the last(if) condition fails, I want to increment the value of i and proceed further. This code just stops execution on failure and doesn't increment the value.

share|improve this question
The check if(count2!=0) inside the loop is redundant, because if count2==0, the program will not enter the loop at all. –  dzieciou Mar 9 '14 at 21:49
It would help also if you provide us with what your app printed to stdout. –  dzieciou Mar 9 '14 at 21:51
What do you mean with "failure"? Are you getting an exception? –  FDM 2 days ago

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.