Question

I'm looking for an opportunity to manipulate the contents of a Web page in browser engine(C#) jquery-like methods. Pseudo-code:

Browser.Document.Query("div.content> a")[0].Click();

I watched the popular browser engines for .NET, but have not found anything like that. Any ideas?

Was it helpful?

Solution

Sounds like, from your description, you want Selenium.

Selenium automates browsers. That's it. What you do with that power is entirely up to you. Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.

Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. It is also the core technology in countless other browser automation tools, APIs and frameworks.

It will allow you to automate a ton of different things, but for example you can navigate to pages within a browser (whether this is Firefox, IE, Chrome etc) and find elements, click them, change their text and execute arbitrary Javascript too.

Selenium has an API in various languages, one of which is indeed C#. You can query against a page using many different methods including CSS selectors (which you use in your example).

OTHER TIPS

The Sizzle engine is what powers jQuery selectors, you might want to look at the Fizzler port:

Check this out: http://code.google.com/p/fizzler/

You probably won't be able to call it directly from C#, but you should be able to create a javascript function in that page that does what you want, and then call that javascript function instead from C#.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top