hello_abhishek
hello_abhishek

Reputation: 545

How to select the location from a field which fetches result from google map api using selenium webdriver(Java)

enter image description here

I have tried entering the complete field value using selenium but this doesn't work. It requires to select from the suggestion shown. Anyone knows how to select from the suggestion show.

Note: I am using hybrid framework.

Upvotes: 2

Views: 2335

Answers (2)

Mohamed Azeez
Mohamed Azeez

Reputation: 1

Just use sendKeys(Keys.Arrow_Down); until the address you need and then use sendKeys(Keys.Enter);

Upvotes: 0

shank087
shank087

Reputation: 492

something like the below one? If yes, replace Thread.sleep with explicit waits.

        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.co.in/maps?source=tldso");
        Thread.sleep(3000);
        driver.findElement(By.id("searchboxinput")).sendKeys("Kora");
        Thread.sleep(3000);
        List<WebElement> autoSuggestions=driver.findElement(By.className("sbsb_b")).findElements(By.tagName("li"));
        for (WebElement suggestions : autoSuggestions) {
            if (suggestions.getText().contains("Koramangala Police Station")) {
                suggestions.click();
                Thread.sleep(3000);
                break;
            }
        }
        driver.quit();

Upvotes: 2

Related Questions