Any way to automate IE *WITHOUT* using webbrowser control? - c#

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);

Related

Is there any way to fully control browser from application?

I was trying to make a pc application that helps people more conveniently when they are using a browser(e.g Chrome, Firefox, Edge ...)
For example, the application shows the default browser and let user can choose another browser as default if they want to, and the app shows all windows that are currently opened; Overmore, when the user clicks a specific window then app will focus the window.
user can select default browser
user can see all windows categorized by browser type
So, my initial planning was using Election js; however, I've found that there is no way to control a browser from the Electron application since Node js cannot access the users' system(this thinking could be wrong since I have poor English😥)
After some research, I'm guessing C# can do that by using windows api. I've saw this post that saying by using DDE, we can get tabs urls.
But I'm wondering if C# can fully control a browser; for instance, create a new window, notice if music or video is playing in the tab, request to browser for getting favorites list.
If it cannot, how about requesting api to the browser from pc application?
You cannot fully control a browser. Internet Explorer was the only browser that had a documented and supported API to control, inspect and automate. Internet Explorer is dead so this is a dead end. The basic DDE control interface is also outdated.
Accessing favorites and the content of open tabs is limited because evil people would use such APIs to inject and spy. If you want to access the favorites you will have to write custom code for each browser.
Using the accessibility and UI automation APIs is the only reliable and supported way of interacting with modern browsers. SetWinEventHook can be used to detect window creation and primitive state changes. MSAA/UI Automation needs to be used to get more information from each browser window.
The thumbnail API and/or magnifier API can be used to get the preview image.
To open a new tab, execute a new process with the URL on the command line. Some per-browser customization might be required (-new-tab parameter etc).
Use IApplicationAssociationRegistration::QueryCurrentDefault to detect the default browser.

How to communicate with Google Chrome using C# or Python

I'm developing a software on C# which has to get info from a website which the user opens in chrome, the user has to input some data and then the website returns a list of different items.
What I want is a way to be able to access to the source code of the page in order to get the info, I cant open the web myself as it doesnt show anything because I didnt input any data, so I need to get it directly from chrome.
How can I achieve this ? A chrome extension ? Or can I access to chrome directly from my software ?
Off the top of my head, I don't know any application that gets data directly from an open instance of Chrome. You'd have to write your own Chrome extension.
Alternatively, you can open the web browser from your application initially.
You can look into these libraries for doing so:
Watin (My personal favourite)
Selenium
Awesomium (You'd have to roll out your own UI, it's invisible)
Cef
Essential Objects Web Browser
EDIT: I didn't think about using QA tools as the actual browser hook as #TheAnathema mentions. That would probably work for your needs.
You're going to need to create it as Chrome extension if you must be dependent on the user actually going to a specific web site (i.e. not being able to do the requests yourself with either Selenium or standard web requests in Python).
The reason why a Chrome extension would be required is because think of how bad it could be for any software to easily read the pages you browse. Banking, medical, email, etc. could all be accessed anonymously from any process if Google allowed any outside process to tap into the web page.
Even Chrome extensions have to ask for permission to be able to do what they want, but at least it is software the user knowingly installed and agreed to the permissions.
A quick search yielded this example of modifying a page's HTML with a Chrome extension: https://blog.lateral.io/2016/04/create-chrome-extension-modify-websites-html-css/
It sounds like you want to do web scraping. Here's a good tutorial to get you started: HTML Scraping.
And this answer has a good example of how to scrape data from a website where you need to submit a form to get access to the data.

Webbrowser control issue with cookies

i have created web browser control in c#. I used to open .net website into this control. Once page is completely loaded.i was using cookies of this browser control to create httprequest and used to execute request. I used to get data which was needed for me.
But all of sudden this stopped working. I checkd to see what happened then i found that issues are with cookies are being formed throught browser control.For example, if i use page url on IE browser and then get cookie and supply it to httprequest. It works good. But same thing with web browser control is not working now.
Another thing, Forget about httprequest, Download from webbrowser control itselft is also failing. But its working in IE. What could be stopping it to download fail in web browser control and work in IE.
Dont understand how.please help.
This issue is not with the cookies. it is with the browser emulation. By default webbrowser control take IE emulation. but if you need to mention which browser version you want control to use. By using registry.
I emulated IE to my application by changing registry information. and it started working.

Open Website containing Javascript code

I want to open some websites which may contain javascript code for example google analytics or piwik. I think the using a webclient is the easiest way to visit websites but does the webclient run javascript code in the background automaticly or how could I get javascriptcode running by visiting a website in C#?
Have you considered using a headless browser like PhantomJS.
If you are looking for something with a UI interface, look at the WebBrowser Control.
If you need to just get the DOM or underlying elements of the DOM, I would suggest Watin. It is very mature and works well and its fast.
WebClient only loads data from the web. It does not interpret it in any way.
If you need to treat the page the way a web browser would, then you need to use a Web Browser control.
in C# there is an Internet Explorer control. You can execute javascript code on a client PC by setting web URL link to this control. Internet Explorer control is a fully functional browser which executes all client code.

How to allow blocked content in an embedded Webbrowser in c#?

I'm developing a c# application that embeds the Webbrowser control. I create the Website dynamically and use NavigateToString() to display it. I'm on Windows 8 with IE10.
Now my Problem is: Javascript won't execute. For example I added a link that calls alert and another one that calls reset() on a form. Both do nothing. I believe it has to be some security issue because when I say the generated page and open the file manually in IE10 and click one of those links, I get a popup at the bottom that says "Internet Explorer restricted this Webpage from running scripts or ActiveX controls." and a "Allow blocked Content"-button. If I just Close the popup, nothing happens, if I click "Allow blocked Content" the JavaScript works fine.
How can I enable JavaScript in the embedded Webbrowser?
How are you accessing this local website? is it localhost? you need to make the url security friendly so it doesn't get blocked, give it a url http:// localhost:someport instead and it should work

Categories

Resources