Ranorex

English|Deutsch

Getting Started

print friendly page

This first step by step example explains how one can automate a simple mouse click on a web element within a web page using RanorexNet.dll and Microsoft Visual Studio.

1. Create Visual Studio Project – “Ranorex Web Test”

Open Visual Studio and create a new “Console Application” named “Ranorex Web Test”.

2. Setup project settings

Now configure your project settings and append the required RanorexNet.dll reference from the Net2.0-Pro directory  to your project References node. The RanorexNet.dll provides the interface required for WebTesting.

Note: Please make sure that your build output folder (Project | Ranorex Web Test  Properties) contains RanorexCore.dll, RanorexNet.dll, Microsoft.mshtml.dll and SHDocVw.dll.

3. Implement web automation code

Before implementing our Ranorex web automation code, we first append two Ranorex specific lines of code using directives - one for normal Ranorex functionality and one for WebTesting usage. The static main routine only requires three code lines to get a mouse click on a web element automated.

C#


using System;
using System.Collections.Generic;
using System.Text;

using Ranorex;
using Ranorex.Web;

namespace WebTesting
{
   class Program
   {
       [STAThread]
       static void Main(string[] args)
       {
           // Starting Internet Explorer
           WebDocument webDoc = WebDocument.OpenDocument
                         ("www.ranorex.com/products/overview.html", true);
           // Find desired web element with RanoreXPath 
           // copied from Ranorex WebSpy
           WebElement webElement = webDoc.FindSingle("//a[text()='link-name']");
           // Click on web element
           Mouse.ClickWebElement(webElement);
       }
   }
}

VB.NET

Imports System
Imports System.Collections.Generic
Imports System.Text

Imports Ranorex
Imports Ranorex.Web

Module WebTesting

    Sub Main()
        ' Starting Internet Explorer
        Dim webDoc As WebDocument = WebDocument.OpenDocument("www.ranorex.com/products/overview.html", True)
        ' Find desired web element with RanoreXPath
        ' copied from Ranorex WebSpy
        Dim element As WebElement = webDoc.FindSingle("//a[text()='link-name']")
        ' Click on web element
        Mouse.ClickWebElement(element)

    End Sub

End Module

4. Analyze a web page with Ranorex WebSpy

To automate a mouse click on a specific web element, it is necessary to first identify the desired web element with Ranorex WebSpy. To do this, start Ranorex WebSpy from your installation folder (start menu) and navigate to www.ranorex.com/products/overview.html.

Now use the “HotTrack” functionality by moving your mouse over the preferred web element. Then press the <CTRL> key to read all the information from the web element currently located under your mouse pointer.

Check the 'Optimize' box and copy your optimized RanoreXPath into the clipboard.

5. Finish implementation – Start Ranorex Web Test application

Paste the copied RanoreXPath into your existing code to finish your first web test application.

C#

...
// Find desired web element with RanoreXPath 
// copied from Ranorex WebSpy
WebElement webElement = webDoc.FindSingle
                ("//area[@title=’Premium Edition’]");
// Click on web element
Mouse.ClickWebElement(webElement);
...

VB.NET

' ...  
' Find desired web element with RanoreXPath   
' copied from Ranorex WebSpy  
Dim element As WebElement = webDoc.FindSingle("//area[@title=’Premium Edition’]")
' Click on web element  
Mouse.ClickWebElement(element)
' ...

Now rebuild and start your first Ranorex Web Test application from Visual Studio. (Debug | Start)