EDIT: Here it is a minimal project which reproduces the compilation error: https://github.com/osmarramso/Javafx-Error/tree/master/Javafx-import-error
I am trying to click an Element from a webview. This element is a button without id or something like that, so I have to rescue it with Xpath. Now I know that it is an HTMLElementImpl, which have the click method. The problem is coming when I try to cast the Element rescued to HTMLElementImpl. When I try to import the relevant package, Intellij orders me to add "--add-exports javafx.web/com.sun.webkit.dom=" to my compilation options, but when I try to compile with maven it returns me the "package com.sun.webkit.dom is not visible" compilation error.
I have seen other replies with solutions like add "--add-exports=javafx.web/com.sun.webkit=ALL-UNNAMED" compilation option or do it in pom.xml like this:
<configuration>
<mainClass>org.openjfx.App</mainClass>
<compilerArgs>
<arg>--add-exports javafx.web/com.sun.webkit.dom=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
This is the code where I am trying to cast Element to HTMLElementImpl:
Document doc = we.getDocument();
Element inputField = null;
try {
inputField =
(Element) XPathFactory.newInstance().newXPath().evaluate("//*[@class=\"ma-NavigationTopNav-mainActions-desktop\"]",
doc, XPathConstants.NODE);
} catch (XPathExpressionException e) {
e.printStackTrace();
}
if (inputField != null) {
HTMLElementImpl t = (HTMLElementImpl) inputField;
LOGGER.log(Level.INFO, "DENTRO "+t.getClass()+" "+t);
t.click();
}
Here maven dependecy:
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-web -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>16</version>
</dependency>