Hi I'm currently trying to get a script that will fill in login details on a site and the submit the form and allow me to gather information from the next page. So far I've managed to fill in the form but I can't get it to submit. I've tried the .click on the button and submit() but neither work. So now I've turned to JavaScript to activate the button. Unfortunately this gives me the error below. I've tried to override the error but I may have done that wrong. Does anyone know how I can submit the form?
This is the error I believe brings my code to a halt
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Exception in thread "main" org.openqa.selenium.WebDriverException: com.gargoylesoftware.
htmlunit.ScriptException: ReferenceError: "console" is not
defined. (https://extbasicph05.podc.sl.edst.ibm.com/FFAMobileRelay/js/ion.sound.min.js#2)
This is my code
public class Main {
public class MyHtmlUnitDriver extends HtmlUnitDriver {
@Override
protected WebClient modifyWebClient(WebClient client) {
//currently does nothing, but may be changed in future versions
WebClient modifiedClient = super.modifyWebClient(client);
modifiedClient.getOptions().setThrowExceptionOnScriptError(false);
return modifiedClient;
}
}
public static void main(String[] args) {
WebDriver driver = new HtmlUnitDriver(true);
driver.get("url");
WebElement usr = driver.findElement(By.id("username"));
WebElement psd = driver.findElement(By.id("password"));
WebElement btt = driver.findElement(By.id("btnLogin"));
usr.sendKeys("username");
psd.sendKeys("password");
String eventScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('"
+ "click"
+ "', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('"
+ "onclick"+ "');}";
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(eventScript, btt);
System.out.println("Page title is: " + driver.getTitle());
}
}