Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

277
Vistas
How to change my Selenium code to HtmlUnit

I have the sellinium code below and it working fine. What I want is to convert this code to be in HtmlUnit. I can use the HtmlUnitDriver like WebDriver driver = new HtmlUnitDriver();

I want to use a pure HtmlUnit. Below my sellinium code is a tried and failed HtmlUnit code.

import java.util.logging.Logger; 
import org.eclipse.jetty.util.log.Log; 
import org.eclipse.jetty.util.log.StdErrLog; import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.htmlunit.HtmlUnitDriver; import com.gargoylesoftware.htmlunit.BrowserVersion; 

public class SpribeDemoTesting { 

public static void main(String[] args) { 

System.setProperty("webdriver.chrome.driver","path to chromedriver.exe");  

driver = new ChromeDriver();

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

WebDriverWait wait = new WebDriverWait(driver,30); 

driver.get("https://www.spribe.co/games/aviator"); 

htmlButton3 = (HtmlButton) htmlPage.getByXPath("//div[@class='modal-content']//button[1]");

Can someone give me an example. //HERE, HOW DO I PASS THE NEWLY OPENED WINDOWS LIKE I WOULD DO THIS IN SELENIUM **Set windows = driver.getWindowHandles();  List windowsH = new ArrayList<>(windows); driver.switchTo().window(windowsH.get(1)); **

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can ask the WebClient for the List of current windows

webClient.getWebWindows()

and then you can ask one of the Windows to get the containing page.

getEnclosedPage()

Usually you have to cast the page to HtmlPage and then you can proceed with the page.

And BTW - there is a major error in your code

webClient.waitForBackgroundJavaScript(30);

is not an option; this call waits for the scripts to finish at the moment you call this. Or in other words, you have to place this call after some action (e.g. click()) to wait for the js if there was some async js triggered.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda