I am a newbie to Selenium. I am running a script which opens Static dropdown but it is providing error. Could anyone please help me out?

My code:

package basics;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class SpiceJetWebUIControls {

    public static void main(String[] args)  {
        // TODO Auto-generated method stub
        WebDriver driver=new FirefoxDriver();
        Select s=new Select(driver.findElement(By.id("ct100_mainContent_dd1_Adult")));

        s.selectByVisibleText("9 Adults");


Error provided:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: #ct100_mainContent_dd1_Adult


Your By.id() is wrong. I visited the site, looked at the sources and you used DD1 while the site uses DDL in their id. (ct100_mainContent_dd1_Adult vs ctl00_mainContent_ddl_Adult)

In some fonts the 1 and l look very similar. Make a habit of using cut and paste and try to minimize the code you type manually. This is very important for variables-, function-, class-names and webdriver selectors.

NoSuchElementException means that the element does not exist at the time you try to access it. It could have multiple reasons:

  • Wrong selector (this is your case I think)
  • Not yet there: The page is still loading. Use the WebDriver wait to wait for the element to appear.
  • Disappeared: Was there, but when you try to use it is gone.
  • Yes,I found that that the error is specific to site as it worked for other sites for me.Thankyou soo much for identifying.Got it.
    – NeHa NeHz
    Oct 14 '17 at 13:04
  • I tried again with the modified code and got an error- Error parsing extensions state: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND)
    – NeHa NeHz
    Oct 14 '17 at 13:15
  • Hmm not sure, better ask a new question. Googling resulted in some people suggestion to upgrade everything to the latest version. sqa.stackexchange.com/questions/29223/… Oct 14 '17 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.