Skip to content

Commit

Permalink
fix with the internal structure change of HtmlUnitDriver.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmi committed Aug 17, 2022
1 parent aa59226 commit a97bb31
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/jp/vmi/selenium/webdriver/HtmlUnitConsole.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jp.vmi.selenium.webdriver;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
Expand Down Expand Up @@ -29,15 +30,15 @@ private HtmlUnitConsole() {
*/
public static void setHtmlUnitConsole(WebDriver driver) {
try {
Field f = driver.getClass().getDeclaredField("webClient");
f.setAccessible(true);
WebClient webClient = (WebClient) f.get(driver);
Method m = driver.getClass().getDeclaredMethod("getWebClient");
m.setAccessible(true);
WebClient webClient = (WebClient) m.invoke(driver);
WebConsole webConsole = webClient.getWebConsole();
com.gargoylesoftware.htmlunit.WebConsole.Logger logger = webConsole.getLogger();
if (logger != null && logger instanceof HtmlUnitConsole)
return;
webConsole.setLogger(INSTANCE);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
log.warn("Cannot set htmlunit console.", e);
return;
}
Expand Down

0 comments on commit a97bb31

Please sign in to comment.