I have a light iPad app that I have loading WKWebViews and displaying them just on the iPad screen. One of the pages I need to be able to login without actually touching the screen so I'm trying a JS injection.
if(room == "Test"){
let jsScript = """
window.onload = function init(){
var username = myUsername;
var password = myPassword;
var usernameInput = document.getElementById('username');
var passwordInput = document.getElementById('password');
var signInButton = document.querySelector('button[type="submit"]');
usernameInput.value = username;
passwordInput.value = password;
signInButton.click();
return;
};
"""
webViews[0].evaluateJavaScript(jsScript) { (value, error) in
if let error = error {
print("Error filling login: \(error)")
}
}
I have a list that stores all the webViews. In this case I only have one page and it is the one I need to login to. It loads properly but I either get that an object type is null from the JS when pulling the usernameInput or passwordInput or that the JS has the wrong return type.
I have tried changing the return type, I've also inspected the page to make sure the ids are correct and they are, and the button has no id but is of type submit.