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
 System.out.println(allLinks.size());
 // display the text for each link on the page
 for( int i=0; i<=allLinks.size(); i++)
 { 
    //display text for each link
    System.out.println(allLinks.get(i).getText());
    //perform click action
    allLinks.get(i).click();
    //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++)
    {
       if(count2!=0)
       {
          // 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

put on hold as unclear what you're asking by Niels van Reijmersdal, Helping Hands, Kate Paulk, PaulDonny, testerab Apr 23 at 23:36

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the 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 Apr 19 at 6:48