Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
¿Por qué HtmlUnitDriver no ubicaría WebElements pero FirefoxDriver podría ubicar los mismos WebElements?

Tengo una pregunta.

Lo que hace que FirefoxDriver pueda ubicar WebElements y hacer clic en ellos en un código Java, pero cuando se ejecuta el mismo código con HtmlUnitDriver, no se ubican los mismos WebElements. Además, cuando se ejecuta el mismo código en HtmlUnit (aplicando los principios de HtmlUnit), no se encuentran WebElements, de hecho, el código devuelve NullPointerException. ¿Hay alguna razón en particular?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Sin ver su código, podría arriesgarme a adivinar que podría deberse a que necesita habilitar javascript.

JavaScript está deshabilitado de forma predeterminada en HtmlUnitDriver.

Si observa el constructor fuente en ( LICENCIA Apache 2.0 )

https://github.com/SeleniumHQ/htmlunit-driver/blob/master/src/main/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.java#L166

 /** * Constructs a new instance, specify JavaScript support * and using the {@link BrowserVersion#getDefault() default} BrowserVersion. * * @param enableJavascript whether to enable JavaScript support or not */ public HtmlUnitDriver(boolean enableJavascript) { this(BrowserVersion.getDefault(), enableJavascript); }

Y los otros constructores en https://github.com/SeleniumHQ/htmlunit-driver/blob/master/src/main/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.java#L143-L158

 /** * Constructs a new instance with JavaScript disabled, * and the {@link BrowserVersion#getDefault() default} BrowserVersion. */ public HtmlUnitDriver() { this(BrowserVersion.getDefault(), false); } /** * Constructs a new instance with the specified {@link BrowserVersion}. * * @param version the browser version to use */ public HtmlUnitDriver(BrowserVersion version) { this(version, false); }

Verá que proporcionan un falso predeterminado si no se proporciona la variable.

Entonces, para habilitar javascript en HtmlUnitDriver, deberá proporcionar verdadero al inicializarlo, que desea que los componentes de JavaScript estén activos en él.

 WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_38, true);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!