RE: Selenium Web Driver and OpenLayers 2.x – (Request number 2): How to do an identify on a map?

Hi all,

this a new question on this stuff. The previous one on a simpler use case, is this one and the response  that Virender Singh  (thanks a lot!) gave me it’s working in that case.

My new request is about the same functionality  but in a more complex web application, and with features on the map that are not markers, but in this case the map is buil completely server side so I need to give to OpenLayers the coordinates of my click on the viewport, then will be the OpenLayers javascript libraries that knows how to manage this coordinates.

Here you’re my java code that, at the moment, doesn’t work

package myTestProjects;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.interactions.Actions;

public class aeraTest_04 {

private static WebDriver driver = null;

public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
//Create a new profile and load my Firefox Test profile
System.out.println(“Creo un nuovo profilo e vi carico il profilo Firefox di test con DEMO 27 …”);
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffProfile = profile.getProfile(“default”);

// Create a new instance of the Firefox driver using my Firefox Test profile
System.out.println(“Creo una nuova sessione del browser Firefox …”);
driver = new FirefoxDriver(ffProfile);

//Put a Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// It is always advisable to Maximize the window before performing DragNDrop action
System.out.println(“Massimizzo la finestra del browser …”);

//Launch the “Sistema Piemonte” Home Page
System.out.println(“Mi collego a AERA Piemonte …”);

// Close the modal browser window to select layers
System.out.println(“Chiudo la finestra modale di selezione layers …”);

// Change the basemap setting OpenLayers as basemap
System.out.println(“Modifico la mappa di sfondo impostano OpenLayers (RadioButton) …”);
WebElement baseRadioButton = driver.findElement(By.xpath(“/html/body/div[1]/div/div[1]/div[2]/div[2]/div/div/div/div/div/div/div/div/div/div/div[2]/div/div/div[1]/div[2]/div[2]/div/div/div/ul/div/li[3]/ul/li[3]/div/input”));;

// Create a new Action instance
System.out.println(“Creo un oggetto di tipo \”Action\” …”);
Actions act = new Actions(driver);

// Find the viewport inside in witch there is the map
System.out.println(“Individuo il viewport al cui interno c’è la mappa …”);
WebElement el = driver.findElement(By.xpath(“/html/body/div[1]/div/div[1]/div[2]/div[2]/div/div/div/div/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div[2]/div[3]”));

// Click on the identify button
System.out.println(“Seleziono il bottone dell’identify …”);

// Perform the click operation that opens new window
System.out.println(“Identify marker at 730, 504 …”);
act.moveToElement(el, 730, 504).click().build().perform();

// Print TEST = OK!!
System.out.println(“TEST = OK !!”);



You can execute this code because my application is public on the web.

To execute manually:

1) close the first modal dialog that appears when the web application starts
2) in the toolbar over the map, click on the blue button with an “i”
3) click on the map where there are points

You’ll see a pop-up appears with some information inside.

This is what I’d like to wee after my click on the map in my java test code.

Thank you very much in advance!!


cesare Train Asked on June 30, 2015 in Selenium WebDriver.
Add Comment
3 Answers

Hi Cesare,

You are in a tough situation there, GeoExplorer is a JavaScript app developed using OpenLayers. These images and the dots that are present on the map are actually layer objects from OpenLayers.

I tried to look at the source code of GeoExplorer from the browser. It is very complex to understand without having a the developer who developed this page. So coming back, its is very hard to write stable tests using Selenium for GeoExplorer. The best way to deal with this application will be to have Javascript tests. You will need to sit with your developers to understand what are the different classes that you can use and directly click on the dots via JavaScript. I was only able to decode a few items and the below code will give you an idea about it

WebDriver driver = new FirefoxDriver();


JavascriptExecutor exe = (JavascriptExecutor) driver;

Object t = exe.executeScript("return georeferences_data.toString();");

System.out.println("All coordinates " + t.toString());

Object obj = exe.executeScript("var layers =; return layers[0].name;");

Object obj1 = exe.executeScript("var layers =; return layers[1].name;");

Object obj2 = exe.executeScript("var layers =; return layers[2].name;");

Object obj3 = exe.executeScript("var layers =; return layers[3].name;");


here I am able to get different layers and coordinates of the dots. By going in this line and taking help from developer will get us near to the solution. I am sorry I was only able to decode this much. Do let me know if you  need more help.


Professor Answered on July 1, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.