Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
string entry = Titleentry.Text;
            webBrowser1.Navigate("http://www.bookdepository.com/search/advanced");

            //HtmlElementCollection bookCollection;

            while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }

            HtmlElementCollection bookCollection = webBrowser1.Document.GetElementsByTagName("input");
            foreach (HtmlElement curElement in bookCollection)
            {
                if ((curElement.GetAttribute("id").ToString() == "searchTitle"))
                {
                    curElement.SetAttribute("value", entry);
                }
            }



            HtmlElementCollection filterCollection = webBrowser1.Document.GetElementById("filterSortBy").GetElementsByTagName("option");
            List<HtmlElement> filterList = new List<HtmlElement>();
            foreach (HtmlElement filterItem in filterCollection) { filterList.Add(filterItem); }
            HtmlElement filterElement =
              (HtmlElement)filterList.Where(filterOption => filterOption.GetAttribute("value").Equals("price_low_high", StringComparison.InvariantCultureIgnoreCase)).SingleOrDefault();

            if (filterElement.GetAttribute("value").Equals("price_low_high"))
            {
                filterElement.SetAttribute("Selected", "price_low_high");
                filterElement.InvokeMember("click");
            }

            bookCollection = webBrowser1.Document.GetElementsByTagName("button");

            foreach (HtmlElement curElement in bookCollection)
            {
                if (curElement.GetAttribute("id").Equals("searchSubmit"))
                {
                    curElement.InvokeMember("click");
                }
            }
            while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }

            MessageBox.Show("Loaded");

            System.Timers.Timer myTimer = new System.Timers.Timer(5000);
            myTimer.Enabled = true;
            myTimer.Start();
            myTimer.Stop();

            if (webBrowser1.ReadyState == WebBrowserReadyState.Complete) //from here on the code doesnt work.
            {
                HtmlElementCollection avCollection = webBrowser1.Document.GetElementById("filterAvailability").GetElementsByTagName("option");

                List<HtmlElement> avList = new List<HtmlElement>();
                foreach(HtmlElement avItem in avCollection)
                {
                    avList.Add(avItem);
                }

                HtmlElement avElement =
                    (HtmlElement)avList.Where(avOption => avOption.GetAttribute("value").Equals("1")).SingleOrDefault();

                if (avElement.GetAttribute("value").Equals("1"))
                {
                    avElement.SetAttribute("Selected", "1");
                    avElement.InvokeMember("click");
                }

                bookCollection = webBrowser1.Document.GetElementsByTagName("button");
                foreach (HtmlElement curElement in bookCollection)
                {
                    if (curElement.GetAttribute("id").Equals("searchSubmit"))
                    {
                        curElement.InvokeMember("click");
                    }
                }
            }

here is the whole code. I tried setting the delay with timer thinking because it is reacting too fast but the timer is also not working so im not sure what the problem could be.

EDIT:

the code that doesnt work is suppose to create the avList with 3 counts and choose the value 1. the value 1 represents the In Stock availability of the website.

when running without debugging it seems to completely ignore the code written in the if condition.

thanks
Posted
Updated 31-Oct-13 2:06am
v3

1 solution

Hi,

I am not so sure about this solution.

In Web.Config File, if you take a look there will be two Files under the "Web.Config" category.

The sub Files of that Branch will be named as
1.Web.Debug.config
2.Web.Release.config


If you are Debugging the File, the Config details will be consumed from the File
.Web.Debug.config
and if you execute the File there is a chance to use the file from common Web.config or the other.

Please check the configure entries are fine and identitical.

Please confirm your observation, so we can help you in this. Also conform what type of Error you are facing or what functionality not working as expected. That will be helpfull for others to guide you.

Thanks!
 
Share this answer
 
v2
Comments
slayasty 31-Oct-13 8:04am    
hi, where can i find this web.config file?
[no name] 31-Oct-13 8:08am    
In Project Folder, what version of Visual studio are you using. In VS 2010, its available in project folder.
slayasty 31-Oct-13 8:23am    
im using VS 2010. thats the first place i looked. I checked each folder of the solution but i dont see any file named web.config or similar
[no name] 31-Oct-13 22:08pm    
Its a web application right, for all web application, for sure the web.config filw wil be available.
If its windows application, the App.config will be available.
slayasty 1-Nov-13 6:45am    
its a WPF application using the systems.web and other related ones. I opening the app.config but the only code that is written is:
<configuration>
<startup><supportedruntime version="v4.0" sku=".NETFramework,Version=v4.0">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900