Looking for help with JMeter and Webdriver to record UI tests. Stuck on selecting a popup window due to Javascript issues...
Here is the current code snippet:
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'])
The issue is that it fails to switch to the popup window after clicking "Quick Entry", resulting in the inability to locate "preselect"...
Seeking guidance from someone who might spot what I'm missing here.
Thank you
UPDATE - Revised the code as per suggestions, but encountering the following error detailed in the log below. The code correctly identifies the window name "APC Overnight Demo Online" but facing an error stating it cannot find a window with that name?
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"