Automating google maps



  • It's very beginners question. I need help about code in automation google maps. I have problems with importing staff (I added jar files but the errors are still here.). Also the code giving me trouble

    package com.company;
    package org.sikuli.webdriver.examples;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.List;
    
    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 Main
    {
        public class VerifyLinks {
    
            public static void main(String[] args)
            {
                WebDriver driver=new FirefoxDriver();
    
                driver.manage().window().maximize();
    
                driver.get("https://www.google.com/maps/");
    
            }
    
            public static void verifyLinkActive(String, "https://www.google.com/maps/")
            {
                try
                {
                    URL url = new URL(https://www.google.com/maps/);
    
                    HttpURLConnection httpURLConnect=(HttpURLConnection)url.openConnection();
    
                    httpURLConnect.setConnectTimeout(3000);
    
                    httpURLConnect.connect();
    
                    if(httpURLConnect.getResponseCode()==200)
                    {
                        System.out.println("https://www.google.com/maps/"+" - "+httpURLConnect.getResponseMessage());
                    }
                    if(httpURLConnect.getResponseCode()==HttpURLConnection.HTTP_NOT_FOUND)
                    {
                        System.out.println("https://www.google.com/maps/"+" - "+httpURLConnect.getResponseMessage() + " - "+ HttpURLConnection.HTTP_NOT_FOUND);
                    }
                } catch (Exception e) {
    
                }
            }
    
            public class GoogleMapExample
            {
                SikuliFirefoxDriver driver = new SikuliFirefoxDriver();
    
                // visit Google Map
                 driver.get("https://maps.google.com/");
    
                // get button Directions
                WebElement button = driver.findElement(By.id("searchbox-directions");
                    button.Click(); // check
    
                // assert that "Car" is choosen CHECK
                // Assert.assertEquals(driver.findElement(By.xpath("//*[@id='errorMessage']")),"Вожња"); /html/body/jsl/div[3]/div[9]/div[3]/div[1]/div[2]/div/div[2]/div/div/div[1]/div[2]/button
                public void byCar()
                {
                    Connection byCar = getConnection();
                    assert byCar == true;
                }
    
                // enter "Budimpesta" as search terms
                WebElement input = driver.findElement(By.id("sb_ifc51"));
                    input.sendKeys("Budimpesta");
                    input.sendKeys(Keys.ENTER);
    
                // enter "Beograd" as search terms
                WebElement input = driver.findElement(By.id("sb_ifc52"));
                    input.sendKeys("Beograd");
                    input.sendKeys(Keys.ENTER);
    
                // click on "Option" to disable highway(id?) CHECK
                //driver.findElement(By.xpath("//span[contains(@section-directions-options-link,'middle') and contains(text(), 'Опције')]"))
                driver.findElement(By.xpath("/html/body/jsl/div[3]/div[9]/div[9]/div/div[1]/div/div/div[2]/button[2]/span[1]"));
    
                // tick checkbox autoputevi - id za checkbox autoputevi, checkbox Id -> pane.directions-options-avoid-highways CHECK
                // string checkboxXPath = "//input[contains(@id, 'lstCategory_0')]"
                //IWebElement elementToClick = driver.FindElement(By.XPath(checkboxXPath));
                //elementToClick.Click();
    
                string checkboxID = "//input[containts@id, 'pane.directions-options-avoid-highways']";
                 IWebElement elementToClick = driver.FindElement(By.ID("pane.directions-options-avoid-highways"));
                 elementToClick.Click();
    
               // The longest route
                WebElement element = driver.findElement(By.id("section-directions-trip-2"));
                element.OnClick();
    
            }
    
            // Checks if distance and time duration are present on details page
            public void verifyTextPresent(String value)
    
            {
                driver.PageSource.Contains(value);
            }
            try
                {
                    Assert.IsTrue(verifyTextPresent("6 с 7 мин"));
                    Assert.IsTrue(verifyTextPresent("373 km"));
                    Console.WriteLine("Distance and time duration is present on  the page");
                }
    
            catch (Exception)
    
                {
                    Console.WriteLine("Distance and time duration is not present on the page");
                }
        }
    
    }
    


  • Hey Igor,

    What is the error message?


Log in to reply