title: JMeter - Webdriver - Multiple windows
body: <p>I Hope someone can help me, I am using JMeter and Webdriver to record some ui tests, but I am stuck on selecting a popup window, my javascript isn't great...</p>
  
  <p>here is what I have -</p>
  
  <pre><code>var pkg = JavaImporter(org.openqa.selenium)
  var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
  var driver = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
  var wait = new support_ui.WebDriverWait(WDS.browser, 5000)
  
  WDS.log.info("Opening page...");
  WDS.browser.get('XXXX')
  
  var userField = WDS.browser.findElement(pkg.By.id('userid'))
  userField.click()     
  WDS.log.info("Clicked user field")
  userField.sendKeys(['XXXX'])
  
  var passField = WDS.browser.findElement(pkg.By.id('password'))
  passField.click()     
  WDS.log.info("Clicked pass field")
  passField.sendKeys(['XXXXX'])
  
  var loginButton = WDS.browser.findElement(pkg.By.cssSelector('input[type=\"image\"]'))
  loginButton.click()
  
  var quickEntry = WDS.browser.findElement(pkg.By.linkText('Quick Entry'))
  quickEntry.click()
  
  
  var handles = WDS.browser.getWindowHandles()
  var iterator = handles.iterator()
  var counter = 1;
  while (iterator.hasNext())
  {
  var handle = iterator.next()
  WDS.browser.switchTo().window(handle)
   WDS.log.info('Window ' + counter + ' title = ' + WDS.browser.getTitle())
  counter++;
  }
  
  WDS.browser.switchTo().window('APC Overnight Demo Online')
  
  var reference = WDS.browser.findElement(pkg.By.name('preselect'))
  quickEntry.sendKeys(['TEST'])
  </code></pre>
  
  <p>The problem is that it isn't switching to the popup window after selecting "Quick Entry" so it can't find "preselect"...</p>
  
  <p>I assume I am missing something and someone here is smart enough to tell me what I am missing</p>
  
  <p>Thanks</p>
  
  <p>UPDATE - I have updated the code to what I now have, but it still isn't working, as you can see from the log below, it finds the name of the window "APC Overnight Demo Online" but the switchto command says it can't find a window with that name?</p>
  
  <pre><code>2016/12/19 14:25:51 INFO  - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: Opening page... 
  2016/12/19 14:25:51 INFO  - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: Clicked user field 
  2016/12/19 14:25:51 INFO  - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: Clicked pass field 
  2016/12/19 14:25:52 INFO  - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: Clicked login 
  2016/12/19 14:25:52 INFO  - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: Clicked quick entry 
  2016/12/19 14:25:52 INFO  - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: Window 1 title = APC Overnight Demo Online - Home Page 
  2016/12/19 14:25:53 INFO  - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: Window 2 title = APC Overnight Demo Online 
  2016/12/19 14:25:55 ERROR - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: Unable to locate window "APC Overnight Demo Online"
  </code></pre>