Saturday, March 28, 2015

How to Automate google maps using selenium ?

package org.sikuli.webdriver.examples;
import java.io.IOException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.sikuli.webdriver.ImageElement;
import org.sikuli.webdriver.SikuliFirefoxDriver;
public class GoogleMapExample {
       
        public static void main(String[] args) throws IOException {
               
       SikuliFirefoxDriver driver = new SikuliFirefoxDriver();        
               
   // visit Google Map
    driver.get("https://maps.google.com/");
   
    // enter "Denver, CO" as search terms
    WebElement input = driver.findElement(By.id("gbqfq"));
    input.sendKeys("Denver, CO");          
    input.sendKeys(Keys.ENTER);

    ImageElement image;
   
    // find and click on the image of the lakewood area
    image = driver.findImageElement(new URL("https://dl.dropbox.com/u/5104407/lakewood.png"));
    image.doubleClick()     ;              
   
    // find and click on the image of the kendrick lake area
    image = driver.findImageElement(new URL("https://dl.dropbox.com/u/5104407/kendrick_lake.png"));
    image.doubleClick();

    // find and click the Satellite icon to switch to the satellite view
    image = driver.findImageElement(new URL("https://dl.dropbox.com/u/5104407/satellite.png"));            
    image.click();

    // find and click the plus button to zoom in
    image = driver.findImageElement(new URL("https://dl.dropbox.com/u/5104407/plus.png"));
    image.click();
   
    // find and click the link button
    WebElement linkButton = driver.findElement(By.id("link"));
    linkButton.click();
                           
        }
}

2 comments:

  1. Bro,good morning I tried the google maps code with SikuliFirefoxDriver but code is not executing error came The error is Exception in thread "main" java.lang.NoClassDefFoundError: org/sikuli/api/Screen
    at org.sikuli.webdriver.examples.googles.(googles.java:20)
    Caused by: java.lang.ClassNotFoundException: org.sikuli.api.Screen
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 1 more
    Bro, you didn't suggest what softwares we need to download and how to download and how to install them in eclipse and If cursor kept on sikuliFirefoxDriver this is coming Note: This element has no attached Javadoc and the Javadoc could not be found in the attached source.Bro, please expalin this sikuli topic one's again.please Bro.Thanking you Bro.

    ReplyDelete
  2. If we are using any other browser except firefox we should follow some other syntax in selenium. It might be the reason. try it in FirefoxDriver class.

    ReplyDelete

TestNG - Can i use the 2 different data providers to same @test methods in TestNG?

public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...