Currently, I am attempting to use Selenium in Java to access a web page. Unfortunately, the site is returning an error message:
Exception in thread "main" org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "require" is not defined.
After consulting with a front end developer, I was advised to load a specific JavaScript script before the page loads. The script in question is called
require.js
, and I was able to locate it at https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.js
I am currently using htmlunit-driver 2.28
.
I have noticed that when initializing the driver as follows:
HtmlUnitDriver driver =new HtmlUnitDriver(true);
An option becomes available:
driver.executeScript(script, args)
This option is missing when using
WebDriver driver =new HtmlUnitDriver(true);
Although I can potentially work around this issue by using HtmlUnitDriver (as my code is already in production for other projects using WebDriver), I am unsure how to utilize the executeScript function to pass a URL for the script.
If anyone could provide guidance on injecting this into my WebDriver, I would greatly appreciate it. Thank you!