0

Is there any way to keep the value in the arraylist even after the page is loaded because I need the stored values for verifying afterwards.

I tried Http Cookie set also but not able to find it. Pls help

 for (int i = 1; i <= random2; i++)
            {
                //   int total_checkbox = Total_Count_Checkbox;


                int div = (int)al[i - 1] / 10; //div is the page number of the element
                int mod = (int)al[i - 1] % 10; //mod is checkbox number of the element

                if (mod == 0)       //for checking inf the number comes to be 10
                {
                    div = div - 1;
                    mod = 10;
                }
                if (div == 0)
                {
                    LiSt3[mod - 1].Click();           //Clicking for the same page elements
                }
                else
                {
                    for (int b = 2; b <= div; b++)         //checking for the other pages
                    {
                        Browser.Click("Saved_Estimates", "Forward_Link_normal");
                        Thread.Sleep(1000);
                    }
                    IList<IWebElement> LiSt4 = driver.FindElements(By.CssSelector(".checkbox.checkbox-success.ng-scope"));
                    LiSt4[mod - 1].Click();             //clicking for the other page elements
                }
                Browser.WaitforthePageLoad();
                IList<IWebElement> LiSt_of_Names_Summary_List = driver.FindElements(By.CssSelector("span[data-bo-bind='item.Name']"));
                IList<IWebElement> LiSt_of_Dates_List = driver.FindElements(By.CssSelector("span[data-bo-bind='item.GeneratedDateString']"));
                IList<IWebElement> LiSt_of_Times_List = driver.FindElements(By.CssSelector("span[data-bo-bind='item.GeneratedTimeString']"));
                IList<IWebElement> LiSt_of_Last_Day_Worked_List = driver.FindElements(By.CssSelector("div[data-bo-bind='item.LastDayWorkedDateString']"));
                IList<IWebElement> LiSt_of_Benifit_Commencement_List = driver.FindElements(By.CssSelector("div[data-bo-bind='item.BenefitCommencementDateString']"));
                Browser.WaitforthePageLoad();

                LiSt_of_Names_Summary_List_Arraylist.Add(LiSt_of_Names_Summary_List[mod - 1]);
                LiSt_of_Dates_List_Arraylist.Add(LiSt_of_Dates_List[mod - 1]);
                LiSt_of_Times_List_Arraylist.Add(LiSt_of_Times_List[mod - 1]);
                LiSt_of_Last_Day_Worked_List_Arraylist.Add(LiSt_of_Last_Day_Worked_List[mod - 1]);
                LiSt_of_Benifit_Commencement_List_Arraylist.Add(LiSt_of_Benifit_Commencement_List[mod - 1]);

                if (div != 0)
                {
                    for (int b = 2; b <= div; b++)
                    {
                        Browser.Click("Saved_Estimates", "Back_Arrow_normal");
                        Thread.Sleep(1000);
                    }
                }
            }
Ruban J
  • 622
  • 1
  • 7
  • 31
  • When is this code executed? onpageload? or what? Is it code that executes in response to a user's actions? or does it execute everytime the page is loaded? – CA Martin May 30 '16 at 06:44
  • yes on page load, there are 10 options per page and I have to select three from any page randomly. For one iteration it is fine but while another it looses the first value in [0]th index and similarly for the second iteratioonit loosed the [1]st values too. But I need all the values – subhajit chakraborty May 30 '16 at 06:48
  • are you saying that a user answers questions on one page, and you need that information saved for the next page load? and so on? If yes then are you familiar with session variables? – CA Martin May 30 '16 at 06:52
  • You can use session or view state for this purpose. If you can tell me the exact scenario then i can help you in deciding what to use. – SHIVANG RANA May 30 '16 at 06:53
  • good suggestion i gave huh? – CA Martin May 30 '16 at 06:54
  • yes it should save the for the next iteration. I am new to it, I tried it with http cookies but with session I have no idea how to do it for the arraylist. Can u tell it for arraylist too – subhajit chakraborty May 30 '16 at 06:55
  • If you want to chat offline.. you can send me more information about the project. – CA Martin May 30 '16 at 06:59

2 Answers2

1

You can do it easily with the help of session.

Session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request.

For more information for the session go to the following link: Session

If you want to store any type into the session you just need to assign it to the session like this

ArrayList aryList=new ArrayList();
aryList.Add(Sample);
aryList.Add(Test);
//to store the array list to the session
Session["AryList"] = aryList;
//or if you have a class file then
HttpContext.Current.Session["AryList"] = aryList;
//to get the values from the session
ArrayList aryList= (ArrayList)Session["AryList"];

For more help refer to the following question: ArrayList Session

Hope it will help you.

Community
  • 1
  • 1
SHIVANG RANA
  • 384
  • 6
  • 25
  • is there any predefined namespace for the Session. I tried with System.web but it still showing name "Session" does not present in current context – subhajit chakraborty May 30 '16 at 07:32
  • http://stackoverflow.com/questions/6969563/session-does-not-exist-in-the-current-context Go to this answer it will help you. Or tell me is it a code behind page or a class file? if the answer is useful to you then mark it as accepted. – SHIVANG RANA May 30 '16 at 08:38
0

Use session variables. You can save a wide variety of information this way, or you can be more elaborate and store information in a database.

You can even use AngularJS and JSON objects etc.. depends on how elaborate you want to get.

CA Martin
  • 307
  • 2
  • 7