Not able to select an item in dropdown using select class | Selenium Forum
M
Posted on 28/10/2016
Hello all,
am trying to select an item from the dropdown list using select class.
But not able to do so as always it is throwing exception No such Element Exception.
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='speed']"}

Link: https://jqueryui.com/selectmenu/
Scenario :Trying to select "Faster" in the Select a speed dropdown.

My code:
@BeforeTest
public void setupbrowser() throws Exception
{

System.setProperty("webdriver.chrome.driver","S:\\Selenium\\Selenium Installation-2\\chromedriver_win32\\chromedriver.exe");
driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://jqueryui.com/selectmenu/");
driver.manage().timeouts().pageLoadTimeout(50, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@Test
public void SelectClass() throws InterruptedException
{
WebElement ele=driver.findElement(By.xpath(".//*[@id='speed']"));
Select sel=new Select(ele);

WebElement selectedoption=sel.getFirstSelectedOption();
System.out.println("The selected option is:"+selectedoption);

List<WebElement> alloptions=sel.getOptions();
int totalitems=alloptions.size();
System.out.println("total items in the dropdown:"+totalitems);


sel.selectByVisibleText("Faster");
System.out.println("Faster is selected");

}

@AfterTest
public void teardown()
{
driver.quit();
}

I have even tried using CSS selector.But didn't work.

M
Replied on 01/11/2016

you have to switch to iframe. module 15.