HtmlUnit / htmlunit-android

HtmlUnit packaged for Android
Apache License 2.0
40 stars 8 forks source link

JavaScriptExecutor doesn't seem to have an 'executeScript' feature #51

Open hammondreg opened 3 months ago

hammondreg commented 3 months ago

I'm trying to access my own banking details (not other peoples!) by clicking on the 'Continue' button of:

https://onlinebanking.nationwide.co.uk/AccessManagement/IdentifyCustomer/IdentifyCustomer

but without success. I have tried a normal 'click()' on the button, but nothing happens no matter how long I wait.

I have already successfully used Selenium in a .Net program to overcome this problem, and whilst the Selenium version (in C#) also seems to ignore a 'click()', when I use:

JavaScriptExecutor.ExecuteScript("arguments[0].click();", targetButton);

it does have the required effect, i.e. the button 'clicks' and I transfer to the next html page so all is good.

Using a similar approach with 'htmlunit-android' however, there doesn't seem to be an extension 'executeScript' that I can use with 'JavaScriptExcutor'. Have I missed something? Is it there under another guise??

Here's the Kotlin snippet (sorry its not Java, but I have to use Kotlin because Java doesn't support co-routines):

import org.htmlunit.javascript.background.JavaScriptExecutor
import org.htmlunit.WebClient
import org.htmlunit.html.HtmlButton
import org.htmlunit.html.HtmlPage

private lateinit var mainScreen : HtmlPage

var webClient = WebClient()     // Create the webClient
var myURL = "https://onlinebanking.nationwide.co.uk/AccessManagement/IdentifyCustomer/IdentifyCustomer"

var mainPage = webClient.getPage(myURL) as HtmlPage        // Retrieve the target page

var jsexecutor: JavaScriptExecutor = webClient as JavaScriptExecutor    // Declare a JS executor

var buttonsList = mainPage.getElementsByTagName("button") as List<HtmlButton> // Find all buttons
for (targetButton in buttonsList )   // Loop round the buttons
{
        if (targetButton.textContent == "Continue") // This is the one I'm looking for
        {
                jsexecutor.executeScript("arguments[0].click();", targetButton) // <= 'executeScript'!! isn't there!
         }
}

Thanks in advance for any assistance

rbri commented 3 months ago

Had a first look - opening the page generates a bunch of js errors. Will have a look.

hammondreg commented 3 months ago

Yes. Its full of errors, I agree. But the Selenium version manages to overcome them (somehow). Its the 'executeScript' feature that is stopping me. But thanks for looking, much appreciated

rbri commented 3 months ago

the first bunch of (simple fixes) are done - now i have to have a look at the tricky ones :-)

rbri commented 3 months ago

step one done, i can load the start page without getting js errors, next step is filling the form, clicking and get the error msg

hammondreg commented 3 months ago

I am waiting with bated breath! =:-]

rbri commented 3 months ago

Found the next problem, a bunch of objects are not working when used from a worker. This will require some time because i like to write a bunch of tests for this.

So please continue breathing for a while