Welcome Guest Search | Active Topics | Sign In | Register

Automation Options
DavidM
Posted: Tuesday, April 8, 2014 5:04:38 PM
Rank: Newbie
Groups: Member

Joined: 4/8/2014
Posts: 2
I currently use the Microsoft WebBrowser WinForms control to control/manage (automate) IE. I'm looking for a better solution.

My application works in the background to navigate to sites that we upload on behalf of authors. We enter 'search' terms to have the browser navigate to our entries and then the application steps through the page DOM looking for our particular entries. When it finds it, the application sets a red border around the item, takes a PDF (or PNG) snapshot of the entire page (even the stuff that is scrolled off) and stores it in our DB for mailing out the 'proof' to the author.

The application runs about 40 browser sessions (in parallel) per machine.

I want to convert this application to EO.

I've looked at the samples in C# (they are woefully limited - there seems to be just one).

I've looked at the Reference documentation.

While there is a bunch there (that's great). None of the entries include sample snippets of code (this is terrible).

Much of the documentation is very 'vanilla' with no in-depth explanation of anything (unfortunately).

So, my request: please provide me with some samples that show browser automation or direct me to where I can see how its done.

I did see the DOM documentation but I can't find a 'Click' method or 'enter text' (for Input tags) or how to pick an option of a SELECT tag - just to name a few of the needs of browser automation.

Please help.. I'd love to switch to EO. I think that Chrome is the best browser around and this is the first package that seems to give me direct access to it.

-Thanks in advance
David
eo_support
Posted: Wednesday, April 9, 2014 3:50:58 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

You will want to use EvalScript for that purpose. For example, to enter text, you can do:

Code: C#
webView1.EvalScript("document.getElementById('your_input_element_id').value = 'some value'");


For click event you can do:

Code: C#
webView1.EvalScript("document.getElementById('your_button_id').click();");


If you are familiar with DOM and JavaScript, these should be rather easy and straightforward for you. While it is technically possible for us to have a complete mirror of the JavaScript side interface on the .NET side, doing so would introduces performance penalty (every call/argument would have go back and forth between JavaScript and .NET), and it would be basically just another wrapper of what's already there. So instead of writing

Code: C#
webView1.EvalScript("document.getElementById('your_button_id').click();");


You would be writing something like:

Code: C#
webView1.Document.GetElementById("your_button_id").Click();


It doesn't make much of a difference and it would give you another stack of documentation which would basically be a copy of the whole JavaScript DOM document, so you either read the "original" JavaScript copy or our copy, thus it doesn't appear to make a lot of sense to us to do so.

When you do automation, the other function you want to take a look would be LoadUrlAndWait, which will probably come handy for your scenario.

Hope this helps.

Thanks!
DavidM
Posted: Wednesday, April 9, 2014 9:50:19 AM
Rank: Newbie
Groups: Member

Joined: 4/8/2014
Posts: 2
I understand your comment regarding the mirroring.

So why do you have any DOM objects (Document, Element, ...)?

The reason I need the DOM is because my current app walks the DOM (provided by Microsoft's WebBrowser control) on the C# side. I don't inject any Javascript into the site's HTML as I automate IE.

This means that the app saves information regarding what nodes it finds while its processing the site.

To use your approach requires a redesign of the my app to inject Javascript that can keep state and do the things the app currently does in C#.

I will explore this approach. Any links to useful samples would be appreciated.
eo_support
Posted: Wednesday, April 9, 2014 12:53:09 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

Yes. We do have a few DOM object classes such as window and document. Those are used very frequently so we feel it might benefit a little to expose them as strong typed object. We are trying to maintain a balance between many factors: usability, performance, maintainability, etc. So in the end we only exposed a few.

You can keep objects in your application with EvalScript as well. For example, you can do:

Code: C#
//Keep a reference of button1
JSObject button1 = webView1.EvalScript("document.getElementById('button1');");


Then later you can do:

Code: C#
//Invoke click function on the button object
button1.InvokeFunction("click");


In fact the source code for WebView.GetDOMWindow() is:

Code: C#
//EvalScript returns a JSObject which points to the DOM window object. It
//then cast it to a strong typed DOM.Window object
return JSObject.CastTo<DOM.Window>(EvalScript("window", false));


In your case, if you prefer strong typed objects, you can implement your own class. For example, if you want a strong typed Button object with a Click method and a "Value" property, you can do it like this:

Code: C#
//.NET side wrapper class for DOM button object
class Button: JSObject
{
    public void Click()
    {
        //This is the same as "button1.click()" in JavaScript
        InvokeFunction("click");
    }

    public string Value
    {
        get
        {
            //This is the same as "button1.value" in JavaScript
            return this["value"];
        }
    }
}


After that you can do:

Code: C#
//Get the DOM button1 object and then cast it to your custom Button type
Button button1 = JSObject.CastTo<Button>webView1.EvalScript("document.getElementById('button1');");


As you can see, everything is pretty much a wrapper around EvalScript and JSObject.

Hope this helps. Please feel free to let us know if you have any more question.

Thanks!



You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.