Synthetic does not find obvious popup

I have tried everything I know to do but the code doesn’t see the obvious popup.

Pop-up windows
How to handle intermittent Pop-up
Trouble with Pop up
Pop-up Handling

Can someone assist?

// Check if element is present; returns true if found
function elementIsPresent(ele) {
	return $browser.waitForAndFindElement(ele).then(function(found) {
		return found.length > 0;
	});
}

.then(function() {
	strLog(1, 'NAVIGATE TO URL: ' + strURL);
	$browser.manage().window().maximize().then(function() {
		// Navigate to site
		return $browser.get(strURL);
	})
})
.then(function() {
	// Wait for page to refresh
	return $browser.sleep(intDefaultTimeout);
})
.then(function() {
	return $browser.switchTo().frame(0);
})
.then(function() {
	// Wait for page to refresh
	return $browser.sleep(intDefaultTimeout);
})
// Get the number of windows displayed
.then(function() {
	return $browser.getAllWindowHandles().then(function(count) {
		intWinNum = _.size(count);
		console.log('The number of windows displayed is: ' + intWinNum);
	});
})
.then(function() {
	return $browser.getWindowHandle().then(function(handle) {
		strOldWindow = handle;
		console.log('initial window is:' + strOldWindow);
	});
})
.then(function() {
	return $browser.getAllWindowHandles().then(function(handles) {
		strNewWindow = _.difference(handles, [strOldWindow])[0];
		console.log('new window is:' + strNewWindow);
	});
})
// Check for popups
.then(function() {
	return elementIsPresent(By.css('a[class$="fancybox-close"]'))
	.then(function(bool) {
		if(!bool) {
			console.log('No pop-up found');
		}
		else {
			console.log('Pop-up found');
			return $browser.findElement(By.css('a[class$="fancybox-close"]'))
			.then(function(el) {
				$browser.executeScript("arguments[0].click();", el);
				$browser.sleep(intDefaultTimeout);
			});
		}
	});
})


Hi @hanastasi Your element inspection shows that the class name is actually “fancybox-item fancybox-close” which could be why it isn’t being found.

I am using the CSS dynamic selector which works on our other sites. For more information on this method, you can visit CSS Selectors.

I have tried using the full name, different “By” types … everything.

Odd. Have you tried the css selector in the browser console? I do this to ensure I am selecting the correct element. Also, does the css selector return more than one element?

I use a local script engine (created by folks at New Relic) to create my scripts, which invokes the browser so I can see how the script if performing. This allows me to select the elements as I develop and provides a better error definition. It’s also not as slow to respond like the New Relic integrated development console.

There is only one element returned

Again, I’ve tried everything

Just wanted to update this thread, as we found the solution separately in a support ticket. The issue was in the elementIsPresent helper function checking element.length of which the length property doesn’t exist, so this helper was always returning false, even when the element was found.

3 Likes

Reason #5346782 why I hate script recorders. :slight_smile:

Anyone willing to write the correct elementIsPresent function?