gpt4 book ai didi

java - Selenium 仅用于测试?

转载 作者:可可西里 更新时间:2023-11-01 11:42:36 24 4
gpt4 key购买 nike

我刚刚开始为 Android 开发应用程序。我写了一些代码,登录到一个网站(使用大量 JavaScript)并获取一些我需要的数据。我用于那个 HtmlUnit。现在我明白了,HtmlUnit 在 android 上不起作用,所以我需要一个替代方案。我做了这样的事情......

final WebClient webClient = new WebClient(BrowserVersion.EDGE);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);

final HtmlPage loginSite = webClient.getPage("...");

final HtmlForm login_form = (HtmlForm) loginSite.getElementById("login_form");

final HtmlSubmitInput button = (HtmlSubmitInput) login_form.getByXPath("//input[@id='login_submit_button']").get(0);

final HtmlTextInput id = login_form.getInputByName("user");
id.setValueAttribute("...");

final HtmlPasswordInput pw = login_form.getInputByName("password");
pw.setValueAttribute("...");

button.click();

webClient.waitForBackgroundJavaScript(2000);

HtmlPage worldSelectionForm = (HtmlPage) webClient.getTopLevelWindows().get(0).getEnclosedPage();

final List<HtmlAnchor> anchorlist = worldSelectionForm.getAnchors();

getWorld(anchorlist, 126).click();
webClient.waitForBackgroundJavaScript(5000);

HtmlPage game = (HtmlPage) webClient.getTopLevelWindows().get(0).getEnclosedPage();
System.out.print(game.asXml());


public static HtmlAnchor getWorld(List<HtmlAnchor> anchorlist, int world) {
HtmlAnchor anchor = null;
for (HtmlAnchor a : anchorlist) {
if (a.toString().contains("server_de" + String.valueOf(world))) {
anchor = a;
}
}
return anchor;
}

我搜索了很多,但没有找到问题的答案。

我也可以用 Selenium 做这个吗? Selenium 仅用于测试吗?

问候

最佳答案

对于“selenium 仅用于测试吗?”这个问题,Selenium site开始于:

Selenium automates browsers. That's it! What you do with that power is entirely up to you. Primarily, it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.

查看 Selendroid ,它取代了 Android Driver .

他们的 Quick Start 上有一些很好的例子页面。

关于java - Selenium 仅用于测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35675673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com