Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium only for testing?

I'm just startet developing apps for android. I wrote some code, with logs into a website(which uses tons of JavaScript) and grabs some data, which i need. I used for that HtmlUnit. Now i see, that HtmlUnit doesn't work on android, so i need an alternative. I did something like this...

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;
    }

I searched alot, but didn't find the answer to my question.

Can i do this too with Selenium? Is selenium only for Testing?

Greetings

like image 652
Muco Avatar asked Mar 03 '26 13:03

Muco


1 Answers

For the question "Is selenium only for Testing?", the Selenium site starts with:

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.

Check out Selendroid, which replaces the Android Driver.

They've got some good examples on their Quick Start page.

like image 112
aneroid Avatar answered Mar 06 '26 03:03

aneroid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!