C# Selenium or WebBrowser alternative mimic human
Asked Answered
T

3

6

Hi all I used Selenium some time ago to create a program to carry out automated actions on a website I enjoy using.

I managed to use Selenium to do what I wanted before without much trouble the only issue I had was using it in the background.

I couldn't use it without it effecting other things I was doing on the PC, I did think of using virtual machines but I would like to try and avoid this.

Last night I was playing around with the WebBrowser class in C# and its nice but limited, I like how it was self contained within the windows form application so this is what I am looking for.

Dose anyone know the best way integrating a visual representation of a browser within a windows form application but still allow me to mimic key entry etc but would run in the background.

I have heard of things like WaitN, GekoFX, MozNet etc but from what I read I am not sure any of these would work.

Turnkey answered 25/2, 2013 at 9:9 Comment(4)
WatiN worked great for me!Schreibman
I looked at WaitN, the last version released was quite a while ago is it still being developed? I just looked at awesomium again it looks like it should work I will give it a try tonight.Turnkey
More recent alternatives listed in guru99.com/selenium-alternatives.html and google.com.au/… and testbytes.net/blog/selenium-alternativesRhesus
Another list of alternatives techcommunity.microsoft.com/t5/testingspot-blog/…Rhesus
L
7

In general, when you are attempting to automate a web page using a browser, you have two options for simulating user events. You can either simulate them via JavaScript, or you can use OS-level mechanisms (so-called "native events") for simulating mouse and keyboard events. Both approaches have their pitfalls.

Simulated events using JavaScript only would probably allow the window being automated to remain in the background, without system focus, while carrying out the tasks you desire. Selenium RC used this method, and Selenium WebDriver offers the ability to use simulated events for Firefox and IE. However, there are some drawbacks to this approach. Simulated events may lack the fidelity and accuracy you require. For example, "drop-down menus" on a page that work via the CSS :hover pseudoselector cannot be triggered via JavaScript, so this approach is doomed to failure in these cases. Additionally, since you're using JavaScript, you're restricted to the JavaScript sandbox, which means that cross-domain frames and the like may be strictly out of bounds.

Native events, on the other hand, are far more closely representational of a user's actual mouse and keyboard operations. In general, they'll allow the correct events to fire on the web page, and in the correct order, without you having to guess which events to fire on which elements. The downside to using them is that to implement them correctly, the window being automated must have the system focus to receive the events properly. You can attempt to hack around this using the SendMessage API if you're on Windows, but this is the Wrong Thing to do, as it's error prone and absolutely not guaranteed to work. The correct way to use native events is to use the SendInput API, but that API sends the input to the window with the system focus. WebDriver defaults to using native events for simulating user input, but it defaults to the flawed SendMessage approach. For IE, at least, it does provide an option to use the more correct SendInput approach.

If you're dead set on not requiring a browser window in the foreground, you really ought to look into a headless option. PhantomJS is a great option, and WebDriver also has a driver for it, which means you can still write your automation code in C#. Otherwise, you're limited to one of the other approaches outlined above.

Laureate answered 25/2, 2013 at 16:53 Comment(1)
Thanks for your explanation of the 2 different options, I think I am going to go with a Javascript method of interaction as the website I am writing this for will work with this route.Turnkey
B
1

Does the application need to be hosted within a window?

I have used selenium, Watin for automation, unfortunately they do interfere with what you are doing and I have not managed to find a way around this.

I have used the .Net WebBrowser class too, but for automating I am not sure without testing if it is a fully featured IE, with regard to JavaScript running inside it. I think it does execute JavaScripts though, but you would need to check.

If you do not need to see what is happening there are headless options available too, even for Selenium I think: Is it possible to hide the browser in Selenium RC?

Here is a list of headless versions if that is viable for you:

https://gist.github.com/evandrix/3694955

Benedictine answered 25/2, 2013 at 9:21 Comment(5)
Well I would prefer some sort of visual representation, I don't think the WebBrowser class is fully featured because I was having loads of problems setting up a auto login to the website which had no problems with selenium, I think there is JavaScript protection on the login which messed up WebBrowser. The goal is to try to make a completely self contained application for this.Turnkey
Just looked at awesomium.com again, I noticed it last night but thought it was C++ only I will see if I can find some C# examples for this before diving into it.Turnkey
Just out of interest, are you running this on a test box as well as a dev box?Benedictine
No I am just running this from my PC to the live version of the website I like, I am developing it in VS 2012 this is just a home project.Turnkey
WebBrowser restricts quite a bit of the available javascript funcitonality. It is the worst choice.Dagger
R
1

From https://learn.microsoft.com/en-us/visualstudio/test/use-ui-automation-to-test-your-code?view=vs-2022

Visual Studio 2019 is the last version where Coded UI Test will be fully available. We recommend using Playwright for testing web apps and Appium with WinAppDriver for testing desktop and UWP apps. Consider Xamarin.UITest for testing iOS and Android apps using the NUnit test framework. To reduce the impact on users some minimum support will still be available in Visual Studio 2022 Preview 4 or later.

Rhesus answered 30/4, 2022 at 10:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.