Tengo la siguiente prueba HtmlUnit en el código adjunto.
¿Cómo hago clic en el BOTÓN CONFIRMAR EDAD emergente?
htmlButton3 = (HtmlButton) getSpribePage.getFirstByXPath("//div[@class='modal-content']//button[1]");El resultado final de la prueba es hacer que el valor cuente.
Cuando vaya a un sitio web manualmente aquí , haga clic en el botón "DEMO", en el botón "CONFIRMAR EDAD" y accederá al juego.
Estoy más interesado en usar un HtmlUnit no 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(); } }