我试着在网站上填充一些元素。一切正常,直到提交按钮不起作用。我什么都试过了,谷歌也帮不了我。
错误是:
Dez 12, 2020 11:09:28 PM com.gargoylesoftware.htmlunit.html.DomElement click
WARNING: Calling click() ignored because the target element 'HtmlButton[<button class="btn-purple btn-big mt2" type="button" id="reg-continue" tabindex="7">]' is not displayed.
代码:
package de.zzzz.main;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Random;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.ScriptException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSelect;
public class Main {
public static ArrayList<String> name = new ArrayList<String>();
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
loadNames("names.txt");
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
WebRequest request = new WebRequest(new URL("https://www.wildz.com/en/register/"));
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setPrintContentOnFailingStatusCode(false);
webClient.getOptions().setRedirectEnabled(true);
webClient.setJavaScriptTimeout(10000);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setTimeout(10000);
webClient.waitForBackgroundJavaScriptStartingBefore(200);
webClient.waitForBackgroundJavaScript(20000);
HtmlPage page = webClient.getPage(request);
// for(HtmlForm f : page.getForms()) {
// System.out.println(f);
// }
HtmlForm form = page.getForms().get(0);
form.getInputByName("email").setValueAttribute("email");
form.getInputByName("password").setValueAttribute("password");
HtmlSelect select = (HtmlSelect) page.getElementById("reg-p-prefix");
select.setSelectedIndex(8);
Random r = new Random();
int phone = r.nextInt((int) (Math.random() * 99999999)) + 10000000;
form.getInputByName("phone").setValueAttribute("22"+phone);
HtmlButton b = (HtmlButton) page.getElementById("reg-continue");
b.click();
//webClient.getWebConsole().debug("document.getElementById('reg-continue').click()");
//ScriptResult result = page.executeJavaScript("document.getElementById('reg-continue').click()");
//System.out.println(result.getJavaScriptResult());
System.out.println(page.getTitleText() + " x 22" + phone);
}
}
我试过这个:
webclient.getwebconsole().debug(“document.getelementbyid('reg-continue').click()”);但这也行不通。当我把它粘贴到我真正的网络浏览器的控制台上时,它就工作了。顺便说一句:按钮显示并启用!
有人能帮我吗?
暂无答案!
目前还没有任何答案,快来回答吧!