简体   繁体   中英

Using loadUrl to get all select options in a drop down box

I'm trying to store all values from a drop down box into variables within my android application. I'm trying to get all options from the below into strings in my app;

<select name="cardId" id="select_card_no" onfocus="null" onchange="null">
<option value="">Choose card number</option>
<option value="010607655930" >010607655930</option>
<option value="050538806749" >050538806749</option>
<option value="054100790989" >054100790989</option>
</select>

I've been using code like this to intially log through parts of the site;

public void onPageFinished(WebView view, String url) {
                if(url == "https://oyster.tfl.gov.uk/oyster/entry.do"){             
                    String ausername = "abcde";
                    String apassword = "12345";
                    view.loadUrl("javascript:document.getElementsByName('j_username')[0].value = '"+ausername+"'");
                    view.loadUrl("javascript:document.getElementsByName('j_password')[0].value = '"+apassword+"'");
                    view.loadUrl("javascript:document.forms[0].submit()");
                }

But was wondering how you could possibly get text back from the current Webview state, can you somehow convert loadUrl into a string;

String ddl = view.loadUrl("javascript:document.getElementById('select_card_no')");

Possible duplicate question. You may want to check out the answer to this one:

android - get Text out of webview

Also, there might be an overall better solution than using this webview approach you're trying. That url does have a developer api: android - get Text out of webview

You may want to try and see if you can get waht you need out of that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM