I want to trigger evaluateJavascript mouse focus by code to document.getElementById('txt_amount'), but it's not working on Windows Desktop. But it's working well on MacOS. When page loaded, I want it to trigger document.getElementById('txt_amount') by mouseFocusEvent, removeAttribute('required') and filled with amountValue2.value = 100 and then click button2 by document.querySelector('button').click() and submit button Continue automatically, But it's not working on Windows Desktop(it's working very well on MacOS).
var amountValue2 = document.getElementById('txt_amount');
if (amountValue2) {
amountValue2.value = 100;
} else {
console.log('amountValue2 not founded.');
}
let button2 = document.querySelector('button');
if (button2) {
button2.disabled = false;
button2.addEventListener('click', function() {
});
var mouseFocusEvent = new MouseEvent('focus', {
bubbles: true, // Allow event to bubble up the DOM tree
cancelable: true, // Allow the event to be canceled
view: window, // Specify the window object
clientX: 0, // Mouse position relative to the viewport
clientY: 0 // Mouse position relative to the viewport
});
amountValue2.addEventListener('focus', function() {
amountValue2.value = $amount;
console.log('Mouse 1 focus!');
});
window.setTimeout(() => {
amountValue2.removeAttribute('required');
amountValue2.dispatchEvent(mouseFocusEvent);
button2.focus();
button2.click();
}, 500);
} else {
console.log('Button not founded.');
}
Image show below