简体   繁体   中英

Any way to automate IE *WITHOUT* using webbrowser control?

I have an enterprise app that automates many business functions. I make heavy use of the WebBrowser control for all of my web site interactions (web site scraping, web app automation, etc....)

I've come across two web sites that simply will NOT render properly in the WebBrowser control. Specifically:

  • the US Postal Service Click-N-Ship web app. Renders fine until it is time to pay for your postage. Even just using the mouse to control it within a WebBrowser control (no automation) will not allow me to pay for postage. Soon as I submit the page it just hangs forever.

  • the UPS Quantum View Manage web app. This page will not even LOAD in the WebBrowser control. Just hangs forever.

Both of these render just fine in my IE10 browser.

I have tried setting the registry keys to change the rendering engine from default IE7 to IE9. But still same results. Something about these web apps just will not render in the WebBrowser control.

So....is there any way to automate IE10 the browser from my C# app? By sending messages of some sort? I need to be able to click links and fill in form data for login info and such. Any advice appreciated...

You could use a testing tool like Selenium to automate IE. You can download the IE Driver from their downloads page.

A simple example using google (Make sure you read the instructions on how to get the IE Driver working):

OpenQA.Selenium.IE.InternetExplorerDriver d = new OpenQA.Selenium.IE.InternetExplorerDriver();
d.Navigate().GoToUrl("http://www.google.com");

d.FindElementByName("q").SendKeys("Stack");
d.FindElementByName("btnK").Click();

WebDriverWait waiter = new WebDriverWait(d, TimeSpan.FromSeconds(10));

waiter.Until(ExpectedConditions.ElementExists(By.CssSelector(".rc .r a")));
// Message the first element
MessageBox.Show(d.FindElementByCssSelector(".rc .r a").Text);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM