I use the HtmlUint3 Android library and I want to get the value of a tag element and update it or send a value to it using JavaScript, or the value is set dynamically through JavaScript after the page loads, but when I access it through the getElementById() function, the value is always empty using the ** library, the value appears in the real browser, whether it is Android or desktop. Also, when you print the text or code, the texts that were executed through the JavaScript code appear inside the code Html.
My page has a group of frames, including the main frame, which is the page menu and controls the other frames, and there is an interconnection between them. If a frame among them is opened on another page, some information is lost. Each frame is filled with data using JavaScript, and here is the problem I face in the line below.
this code not have attribute value But it is filled out using JavaScript code. The Html code does not have a value
<input type="text" name="IdUser" id="IdUser" size="16" maxlength="64">
work fine
<td><script language="javascript">document.write(Info.ProductClass);</script>H738BC </td>
my code
@SuppressLint("SetJavaScriptEnabled")
fun scrapeR(){
CoroutineScope(Dispatchers.IO).launch{
initBrowser()
loadPage()
loginPage()
task()
}
}
suspend fun initBrowser(){
val browserVersion = BrowserVersion.BrowserVersionBuilder(BrowserVersion.CHROME)
browserVersion.setSystemTimezone(TimeZone.getDefault())
webClient = WebClient(browserVersion.build())
// Enabled javascript
webClient.options.isJavaScriptEnabled = true;
webClient.options.isThrowExceptionOnScriptError = true;
webClient.options.isThrowExceptionOnFailingStatusCode = false;
webClient.options.isCssEnabled = true;
webClient.javaScriptTimeout = 10000;
webClient.options.timeout = 10000;
webClient.ajaxController = NicelyResynchronizingAjaxController()
webClient.options.isRedirectEnabled = true
webClient.options.isAppletEnabled = true
webClient.options.isUseInsecureSSL = true
webClient.options.isWebSocketEnabled = true
webClient.cssErrorHandler = SilentCssErrorHandler()
webClient.refreshHandler = ThreadedRefreshHandler()
webClient.cookieManager.isCookiesEnabled = true
webClient.options.isDoNotTrackEnabled = true;
webClient.options.isGeolocationEnabled = false;
webClient.options.isPopupBlockerEnabled = false;
webClient.options.isDownloadImages = false;
webClient.options.isPrintContentOnFailingStatusCode = true;
}
suspend fun loadPage(){
page = webClient.getPage(addressPage)
webClient.waitForBackgroundJavaScript(1000)
}
// This is an independent page that works without problems
suspend fun loginPage(){
val inputFieldUserName = page.getElementById(usernameId) as HtmlInput
inputFieldUserName.valueAttribute = inputUsername
val inputFieldPassword = page.getElementById(passwordId) as HtmlInput
inputFieldPassword.valueAttribute = inputPassword
val butLogin = page.getElementById(buttonId) as HtmlAnchor
page = butLogin.click()
webClient.waitForBackgroundJavaScript(1000)
}
// This is another page
suspend fun task(){
var menuFrame = webClient.getWebWindowByName("menufrm").enclosedPage as HtmlPage
val basicWan = menuFrame.getElementById("User_1") as HtmlAnchor
page = basicWan.click<HtmlPage>()
webClient.waitForBackgroundJavaScript(1000)
var contentFrame = webClient.getWebWindowByName("contentfrm").enclosedPage as HtmlPage
// My problem is here and when printing it appears <input type="text" name="IdUser" id="IdUser" size="16" maxlength="64">
val basicUser = contentFrame.getElementById("IdUser") as HtmlInput
Log.d(TAG,"result = ${basicUser.value}") // and basicWanPppUser, rawValue, defaultValue,nodeValue but empty
webClient.setCurrentWindow(webClient.getWebWindowByName("contentfrm"))
Log.d(TAG,(webClient.currentWindow.enclosedPage as HtmlPage).visibleText)
for (window in webClient.webWindows) {
if (window.enclosedPage != null) {
val framePage = window.topWindow.enclosedPage as HtmlPage
}
}
}
worning
warning: message=[Calling eval() with anything other than a primitive string value will simply return the value. Is this what you intended?] sourceName=[script in http://192.168.1.1/html/status/deviceinfo.asp from (9, 54) to (67, 10)] line=[53] lineSource=[null] lineOffset=[0]
16:45:39.726 W warning: message=[Calling eval() with anything other than a primitive string value will simply return the value. Is this what you intended?] sourceName=[script in http://192.168.1.1/html/status/deviceinfo.asp from (9, 54) to (67, 10)] line=[50] lineSource=[null] lineOffset=[0]
16:45:39.730 W warning: message=[Calling eval() with anything other than a primitive string value will simply return the value. Is this what you intended?] sourceName=[script in http://192.168.1.1/html/status/deviceinfo.asp from (9, 54) to (67, 10)] line=[51] lineSource=[null] lineOffset=[0]
16:45:39.735 W warning: message=[Calling eval() with anything other than a primitive string value will simply return the value. Is this what you intended?] sourceName=[script in http://192.168.1.1/html/status/deviceinfo.asp from (9, 54) to (67, 10)] line=[52] lineSource=[null] lineOffset=[0]
16:45:39.738 W warning: message=[Calling eval() with anything other than a primitive string value will simply return the value. Is this what you intended?] sourceName=[script in http://192.168.1.1/html/status/deviceinfo.asp from (9, 54) to (67, 10)] line=[53] lineSource=[null] lineOffset=[0]
16:45:39.757 I Method exceeds compiler instruction limit: 39878 in int org.htmlunit.cssparser.parser.javacc.CSS3ParserTokenManager.jjMoveNfa_0(int, int)
16:45:40.088 W Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'http://192.168.1.1/lang/wan.res', but got 'text/plain'.
16:45:40.139 W Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'http://192.168.1.1/lang/ethenet.res', but got 'text/plain'.
16:45:41.398 D contentFrame HTMLElement for HtmlTextInput[<input type="text" name="IdPppUser" id="IdPppUser" size="16" maxlength="64">]
1 update in the code
Image
2 update in the Logcat