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

210
Visualizações
How to click a HtmlButton pop-up on the HtmlUnit test

I have the following HtmlUnit test on the attached code.

How do I click a pop-up CONFIRM AGE BUTTON

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

The end result of the test is to get the value counting.

When going to a website manually here, you click the "DEMO" button, "CONFIRM AGE" button and you will be taken to the game.

I'm more interested in using an HtmlUnit not HtmlUnitDriver.

import java.io.IOException; 
import java.net.MalformedURLException;

import com.gargoylesoftware.htmlunit.BrowserVersion;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;

import com.gargoylesoftware.htmlunit.WebClient;

import com.gargoylesoftware.htmlunit.WebClientOptions;

import com.gargoylesoftware.htmlunit.html.HtmlButton;

import com.gargoylesoftware.htmlunit.html.HtmlPage;

import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

public class AviatorHtmlUnit { 

public static void main(String[] args) throws Exception { 

WebClient webclient = new WebClient(BrowserVersion.CHROME);

HtmlButton htmlButton1; 
HtmlButton htmlButton2; 
HtmlButton htmlButton3;

webclient.getOptions().setThrowExceptionOnScriptError(false);

webclient.getOptions().setJavaScriptEnabled(true);

java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.lo gging.Level.OFF);

//webclient.getOptions().setCssEnabled(false);
 webclient.getOptions().setThrowExceptionOnScriptError(false);
 
webclient.getOptions().setUseInsecureSSL(true);
 webclient.getCookieManager().setCookiesEnabled(true);
 
String SprPage = "https://www.spribe.co/games/aviator"; 

HtmlPage getSpribePage = webclient.getPage(SprPage);

//CLICK COOKIE POP-UP BUTTON
//htmlButton1 = (HtmlButton)
getSpribePage.getFirstByXPath("//button[text()=' Got it']"); 

//PLAY DEMO
htmlButton2 = (HtmlButton)
getSpribePage.getFirstByXPath("//button[text()='Play Demo ']"); 

//CLICK CONFIRM AGE BUTTON 
htmlButton3 = (HtmlButton)
getSpribePage.getFirstByXPath("//div[@class='modal-content']//button[1]"); 

//GET NEWLY OPENED  WINDOW
List<WebWindow> windows = webclient.getWebWindows();

webclient.setCurrentWindow(windows.get(1)); 

//GET ROUND COUNTER VALUE 
roundCounter = (HtmlTextInput)
getSpribePage.getFirstByXPath("//div[contains(@class,'coefficient')]");
System.out.println(roundCounter.asText());

webclient.close(); 

     } 
 }

about 4 years ago · Juan Pablo Isaza
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