Reputation: 17011
I have a c# program that uses the Process class to launch Internet Explorer and goes to a url.
It then sends in specific strings to the search box of that page, copies the whole screen of the returned results, and processes it.
The problem I encountered is this:
I use SendKeys.SendWait("abc") to send the string to the page in Internet Explorer (the active window). As the program is running, I see that what is being populated on the page is sometimes "bc", sometimes "abbc", sometimes "abcc", and sometimes correctly "abc". Each run looks totally different. This problem happened on multiple machines I tested. But on my own machine, where I originally developed this, I've never seen it happen - only when I test it on other machines (all running XP).
I put in delays in between SendWait statements to take care of random timing issues, but am I to believe that even within the same SendWait statements there are issues?
Help needed. Thanks.
Upvotes: 1
Views: 1770
Reputation: 4093
If you are attempting to grab source of a web page, then I'd suggest using something like
WebClient client = new WebClient();
client.DownloadString("http://mypage");
If you are attempting to grab the text that gets rendered on the page, then I'd recommend looking at the HtmlAgilityPack which should allow you to much more easily grab the content of the page as well as making it more specific. Alternatively, you could make use of a RegEx to select the text between, say, div tags:
RegEx textSelector = new RegEx("<div>([^<]+?)</div>");
string pageText = "";
foreach(var match in textSelector.Matches(myHtml))
pageText += match.Groups[0].Value;
Warning, that code was written off the top of my head, untested, and will probably result in some pretty random results with nested tags :)
Upvotes: 1