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
    
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 at 21:49
    
It would help also if you provide us with what your app printed to stdout. –  dzieciou Mar 9 at 21:51

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.