Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

276
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda