I have the following Selenium script, which works correctly in Chrome and Firefox:
await driver.get("http://localhost:44180/");
await driver.wait(until.titleIs(RP_LOGIN_TITLE), TIMEOUT);
const emailInput = await driver.findElement(By.name("email"));
await emailInput.sendKeys(JOHN_EMAIL, Key.RETURN);
await driver.wait(until.titleIs(BROKER_CONFIRM_TITLE), TIMEOUT);
const mail = mailbox.nextMail();
const match = /^[a-z0-9]{6} [a-z0-9]{6}$/m.exec(mail);
if (!match) {
throw Error("Could not find the verification code in the email text");
}
const code = match[0];
// await driver.wait(until.elementLocated(By.name("code")), TIMEOUT);
const codeInput = await driver.findElement(By.name("code"));
await codeInput.sendKeys(code, Key.RETURN);
await driver.wait(until.titleIs(RP_CONFIRMED_TITLE), TIMEOUT);
The HTML of the first loaded page looks like:
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="/auth" method="post">
<input name="email" type="email" />
</form>
</body>
</html>
The line that sends the Enter key triggers a form submission, which causes a redirect to a page with the following HTML:
<html>
<head>
<title>Confirm</title>
</head>
<body>
<form id="form" action="/confirm" method="post">
<input
name="session"
type="hidden"
value="NGd7Y-OpQYrZ6wWwZWRKWHyukIVRiu5Pby0bCVshIlQ"
/>
<div class="entry">
<input
name="code"
autofocus=""
type="text"
maxlength="20"
autocapitalize="off"
autocorrect="off"
autocomplete="off"
/><button type="submit">Login</button>
</div>
</form>
</body>
</html>
The call to await driver.findElement(By.name("code"))
throws a NoSuchElementError
. What's interesting, though, is if I add console.log(await driver.getPageSource())
right before that line, the returned HTML has the element. In fact, if I update that line to await driver.findElement(By.css("body"))
I still get a NoSuchElementError
.
I'm using version v4.0.0-alpha.7
of the selenium-webdriver
npm package, version 3.150.1
of the 32-bit IEDriverServer, and IE11 build 11.329.19041.0
on Windows 10 2004.
Does anyone have any ideas why, after form submission and navigation, calls to findElement
throw NoSuchElementError
despite calls like getPageSource
clearly seeing the element?