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

278
Views
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 answers
Answer question

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 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!