Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97813

Selenium send keys (text), selecting from dropdown and hit enter

$
0
0

I'm trying to trawl this website: http://www.jackson-stops.co.uk/

The data is not showing in the URL so I'm using a chromedriver.

My code is:

   public static void main(String[] args) {
    //setup chromedriver
    File file = new File("C:\\Users\\USER\\Desktop\\chromedriver.exe");
    System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
    WebDriver driver = new ChromeDriver();
    try {
        driver.get("http://www.jackson-stops.co.uk/");
        //begin the simulation
        WebElement menu = driver.findElement(By.xpath("//*[@id=\"sliderLocation\"]"));
        ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", menu);
        menu.sendKeys("Knightsbridge");
        Thread.sleep(4000);
        Select menu2 = new Select(menu);
        menu2.selectByVisibleText("Knightsbridge");
        Thread.sleep(4000);
    } catch (Exception exp) {
        System.out.println("exception:" + exp);
        //close and quit windows
        driver.close();
        driver.quit();
    }
    //close and quit windows
    driver.close();
    driver.quit();
}

The error that I get is:

   exception:org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "input"

How would I be able to select a location and hit enter because I tried inspecting the HTML and the options are dynamically loaded so not visible!


Viewing all articles
Browse latest Browse all 97813

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>