I encountered an issue while using selenium-webdriver in JavaScript to input a value into a field. Here is my test.js code:
async () => {
let driver = await new webdriver.Builder().forBrowser("chrome").build();
try {
await driver.get("http://test.com");
await driver.findElement(By.id('user')).sendKeys("test", Key.RETURN);
}catch (e) {
console.log(e);
} finally {
await driver.quit();
}
}
However, I received the following error message in the console:
NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"*[id="user"]"}
(Session info: chrome=80.0.3987.163)
I am confused as the desired field in the HTML looks like this:
<input placeholder="User Name" type="text" id="user" class="input" value="">
Can anyone provide assistance on how to resolve this problem?