I have a javascript where i get the password exposed via an api. I am appending this password to the password field, i can the see the password being masked and also password is correct. but the i am not able to login. if i manually enter the password manually and try logging in, it will work. Not sure whats the issue.
function getElementByXpath(path)
{
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function main()
{
const baseUrl = "API to get passowrd";
const id= '1234';
const params = new URLSearchParams({ id: id});
const url = `${baseUrl}?${params.toString()}`;
let password = "";
token = 'getting from another endpoint'
fetch(url, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`,
'Accept': `*/*`,
'Content-Type': `application/json`
}
}).then(response => response.json())
.then(data => {
password = data.password;
//console.log(data);
var passwordXpath = 'xpath of password field';
var passwordField = getElementByXpath(passwordXpath);
passwordField.type = 'hidden';
passwordField.value = password
//getElementByXpath(passwordXpath).value = password;
})
.catch(error =>{console.error(error);});
}
main();
this is the code. It works for most of the websites. for few of them i am facing this issue. Please help if anyone has a solution