i tried all the options from the stackoverflow site, I'm an intern in programming. Simply indicate how to click.
Site: https://calculator888.ru/random-generator/sluchaynoye-slovo
Button:
<div class="knop_pusk_blok">
<input type="button" id="genr" data-tip="skivo" value="Случайное Слово" class="knop_dstv_vchl">
</div>
Some of my attempts:
ublic class Main2 {
public static void main(String[] args) throws IOException, InterruptedException {
System.out.println("start");
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getCookieManager().setCookiesEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.waitForBackgroundJavaScriptStartingBefore(10000);
webClient.waitForBackgroundJavaScript(10000);
HtmlPage page = webClient.getPage("https://calculator888.ru/random-generator/sluchaynoye-slovo");
List<HtmlElement> countOfWords = page.getByXPath("//*[@id=\"klch\"]");
System.out.println("Count of words is " + countOfWords.size());
List<HtmlElement> setOfWords = page.getByXPath("//*[@id=\"psz\"]");//word!!1111
System.out.println("set of words is " + setOfWords.size());
for (HtmlElement item : countOfWords)
item.setAttribute("data-vpmn", "10");
countOfWords = page.getByXPath("//*[@id=\"klch\"]");
System.out.println("Count of words AFTER is " + countOfWords.get(0).getAttribute("data-vpmn"));
//press button
HtmlInput input = page.getHtmlElementById("genr");
//Html + ButtonInput + Input + SubmitInput
HtmlPage after = input.click();
webClient.waitForBackgroundJavaScript(10000);
for (int i = 0; i < 20; i++) {
if (after.getByXPath("//*[@id=\"psz\"]").size() != 1) {
break;
}
synchronized (page) {
page.wait(500);
}
}
List<HtmlElement> setOfWords1 = after.getByXPath("//*[@id=\"psz\"]");//after
System.out.println("set of words is AFTER CLICK " + setOfWords1.size());
System.out.println("end");
}
}
I've been trying to find a solution for two days now. Thanks for the any help!
EDIT after Cibiyanna26's comment, but still i had same problem:
package org.example;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
WebClient webClient = new WebClient();
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setJavaScriptEnabled(false);
HtmlPage page = webClient.getPage("https://calculator888.ru/random-generator/sluchaynoye-slovo");
webClient.waitForBackgroundJavaScript(10000);
HtmlElement htmlInputLineOfWords = (HtmlElement) page.getByXPath("//*[@id=\"bov\"]").get(0);
System.out.println("before click =" + htmlInputLineOfWords.getTextContent());
webClient.waitForBackgroundJavaScript(10000);
HtmlElement button = (HtmlElement) page.getElementById("genr");
page = button.click();
htmlInputLineOfWords = (HtmlElement) page.getByXPath("//*[@id=\"bov\"]").get(0);
System.out.println("after click = " + htmlInputLineOfWords.getTextContent());
System.out.println(page.asText());
}
}
and pom.xml:
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.13</version>
</dependency>
Ok, this page is a bit tricky but with some hacking we can make it working. The code below works here with HtmlUnit version 3.9.0.