title: Unable to select Bootstrap dropdown in Java Selenium
body: <p>I'm having a very difficult time selecting bootstrap dropdown in Selenium. </p>
  
  <p>I'm new to Selenium so any suggestion and guidance would be very helpful, as what I'd love to do is just select the dropdown, type "email", and press enter during the instance.  </p>
  
  <p>I've gone through dozens of solutions, but none of them have worked for this specific issue. </p>
  
  <p>What can I do? Please help.</p>
  
  <p>Salenium</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>package newPackage;
  
  
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.chrome.ChromeDriver;
  import org.openqa.selenium.interactions.Actions;
  
  
  public class importLeads {
  
   public static void main(String args[]) throws Exception {
    
            System.setProperty("webdriver.chrome.driver", "C:\\Users\\David\\Downloads\\Notes\\WebDriver\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
  
      //login to site
      driver.get("https://demos5.softaculous.com/Mautic/s/contacts/import/new");
      driver.manage().window().maximize();
      driver.findElement(By.id("username")).sendKeys("admin");
      driver.findElement(By.id("password")).sendKeys("password");
      driver.findElement(By.className("btn")).click();
      Thread.sleep(2000);
  
      //importing Data
      WebElement uploadBox = driver.findElement(By.id("lead_import_file"));
      uploadBox.sendKeys("C:\\Users\\David\\Downloads\\data_file.csv");
      driver.findElement(By.id("lead_import_start")).click();
  
      //Select from dropdown
      WebElement dropdownToggle = driver.findElement(By.xpath("id('lead_field_import_email_address')"));
      Actions cursor = new Actions(driver);
      cursor.moveToElement(dropdownToggle);
      cursor.click();
      cursor.perform();
      Thread.sleep(1000);
      WebElement weh = driver.findElement(By.id("lead_field_import_email_address_chosen"));
  
      Actions cursor2 = new Actions(driver);
      cursor2.moveToElement(weh);
      cursor2.click();
  
   }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <hr>
  
  <p>Here is the link to the data file <a href="https://ufile.io/vy2ws" rel="noreferrer">ufile.io/vy2ws</a></p>
  
  <p>In order for the upload of the .CSV file to work, you must be running a local version of this software. Download can be found here: <a href="https://www.mautic.org/m/asset/54:mautic-2100" rel="noreferrer">https://www.mautic.org/m/asset/54:mautic-2100</a></p>
  
  <p>Once uploaded, it should look like this where it asks to choose from the drop-down.</p>
  
  <p><a href="https://i.stack.imgur.com/yGRWe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yGRWe.png" alt="enter image description here"></a></p>
  
  <p>HTML</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="col-sm-4"&gt;
     &lt;div class="row"&gt;
        &lt;div class="form-group col-xs-12 "&gt;
           &lt;label class="control-label" for="lead_field_import_email_address"&gt;Email address&lt;/label&gt;        
           &lt;div class="choice-wrapper"&gt;
              &lt;select id="lead_field_import_email_address" name="lead_field_import[email_address]" class="form-control" autocomplete="false" style="display: none;"&gt;
                 &lt;option value=""&gt;&lt;/option&gt;
                 &lt;optgroup label="Contact"&gt;
                    &lt;option value="email"&gt;Email&lt;/option&gt;
                 &lt;/optgroup&gt;
              &lt;/select&gt;
              &lt;div class="chosen-container chosen-container-single chosen-with-drop chosen-container-active" style="width: 100%;" title="" id="lead_field_import_email_address_chosen"&gt;
                 &lt;a class="chosen-single chosen-default"&gt;
                    &lt;span&gt;Choose one...&lt;/span&gt;
                    &lt;div&gt;&lt;b&gt;&lt;/b&gt;&lt;/div&gt;
                 &lt;/a&gt;
                 &lt;div class="chosen-drop"&gt;
                    &lt;div class="chosen-search"&gt;&lt;input type="text" autocomplete="off"&gt;&lt;/div&gt;
                    &lt;ul class="chosen-results"&gt;
                       &lt;li class="group-result"&gt;Contact&lt;/li&gt;
                       &lt;li class="active-result group-option" data-option-array-index="9" style=""&gt;Email&lt;/li&gt;
                    &lt;/ul&gt;
                 &lt;/div&gt;
              &lt;/div&gt;
           &lt;/div&gt;
        &lt;/div&gt;
     &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <hr>
  
  <p>Replacing :</p>
  
  <pre><code>WebElement dropdownToggle = driver.findElement(By.xpath("id('lead_field_import_email_add‌​ress')")); 
  </code></pre>
  
  <p>to this :</p>
  
  <pre><code>WebElement dropdownToggle = driver.findElement(By.id("lead_field_import_email_address"))‌​;
  </code></pre>
  
  <p>resulted in:</p>
  
  <pre><code>Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 35535
  Only local connections are allowed.
  Oct 22, 2017 1:20:49 AM org.openqa.selenium.remote.ProtocolHandshake createSession
  INFO: Detected dialect: OSS
  Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"lead_field_import_email_address"}
    (Session info: chrome=61.0.3163.100)
    (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
  Command duration or timeout: 0 milliseconds
  For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
  Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
  System info: host: 'DAVID-PC', ip: '192.235.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
  Driver info: org.openqa.selenium.chrome.ChromeDriver
  Capabilities [{mobileEmulationEnabled=false, hasTouchScreen=false, platform=XP, acceptSslCerts=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, platformName=XP, setWindowRect=true, unexpectedAlertBehaviour=, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f), userDataDir=C:\Users\David\AppData\Local\Temp\scoped_dir4068_28713}, takesHeapSnapshot=true, pageLoadStrategy=normal, unhandledPromptBehavior=, databaseEnabled=false, handlesAlerts=true, version=61.0.3163.100, browserConnectionEnabled=false, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}]
  Session ID: ee90469095e7b1121dc2e387d8e485e6
  *** Element info: {Using=id, value=lead_field_import_email_address}
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
      at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
      at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
      at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
      at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
      at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
      at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
      at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:356)
      at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:402)
      at org.openqa.selenium.By$ById.findElement(By.java:218)
      at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
      at newPackage.importLeads.main(importLeads.java:31)
  </code></pre>
  
  <hr>
  
  <p>Replacing </p>
  
  <pre><code>WebElement dropdownToggle = driver.findElement(By.xpath("id('lead_field_import_email_address')"));
      Actions cursor = new Actions(driver);
  </code></pre>
  
  <p>with </p>
  
  <pre><code>WebElement element =  driver.findElement(By.id("lead_field_import_email_address"));
      Select select = new Select(element);
  </code></pre>
  
  <p>resulted in:</p>
  
  <pre><code>Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 32443
  Only local connections are allowed.
  Oct 23, 2017 1:36:09 PM org.openqa.selenium.remote.ProtocolHandshake createSession
  INFO: Detected dialect: OSS
  Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"lead_field_import_email_address"}
    (Session info: chrome=61.0.3163.100)
    (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
  Command duration or timeout: 0 milliseconds
  For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
  Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
  System info: host: 'HOME-PC', ip: '192.235.0.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
  Driver info: org.openqa.selenium.chrome.ChromeDriver
  Capabilities [{mobileEmulationEnabled=false, hasTouchScreen=false, platform=XP, acceptSslCerts=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, platformName=XP, setWindowRect=true, unexpectedAlertBehaviour=, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f), userDataDir=C:\Users\David\AppData\Local\Temp\1\scoped_dir5416_25737}, takesHeapSnapshot=true, pageLoadStrategy=normal, unhandledPromptBehavior=, databaseEnabled=false, handlesAlerts=true, version=61.0.3163.100, browserConnectionEnabled=false, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}]
  Session ID: 40cde314a5a76400aceff8b625b38e3c
  *** Element info: {Using=id, value=lead_field_import_email_address}
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
      at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
      at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
      at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
      at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
      at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
      at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
      at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:356)
      at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:402)
      at org.openqa.selenium.By$ById.findElement(By.java:218)
      at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
      at newAutomation.importLeads.main(importLeads.java:33)
  </code></pre>
  
  <hr>