I am trying to automate a test on my site using selenium web driver for javascript.
How can I approach running tests here using the wait method with content that may not be ready when the page loads eg data comes from an external api etc?
In my example my content is getting loaded by an external js file. You can see what the page looks like in this fiddle I couldn't link it in my code below as the fiddle gets wrapped in an iframe.
<head>
<script src="https://cdn.auth0.com/js/lock/10.2/lock.min.js"></script>
</head>
<body onload="lock.show();">
<div id="content">
<script type="text/javascript">
var domain = 'contoso.auth0.com';
var clientID = 'DyG9nCwIEofSy66QM3oo5xU6NFs3TmvT';
var lock = new Auth0Lock(clientID, domain);
lock.show({
focusInput: false,
popup: true,
}, function (err, profile, token) {
alert(err);
});
</script>
</div>
</body>
I can get it working using sleep, but can't guarentee my content will be ready after the timeout has finished.
const {Builder, By, Key, until} = require('selenium-webdriver');
let driver = new Builder()
.forBrowser('firefox')
.build();
driver.get('MY_URL')
driver.sleep(2000).then(function() {
driver.findElement(By.name('email')).sendKeys('test@test.com')
driver.findElement(By.name('password')).sendKeys('test')
//driver.findElement(By.className('auth0-lock-submit')).click()
})
But if I try with wait
function login() {
return driver.findElement(By.name('email')).sendKeys('test@test.com')
}
driver.get('MY_URL')
driver.wait(login, 5000)
I get NoSuchElementError: Unable to locate element: *[name="email"]
How can I get this working so that I wait for my content to be available before proceeding.