Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hammondreg opened this issue Jul 29, 2024 · 6 comments
Open
Assignees

Comments

@hammondreg
Copy link

hammondreg commented Jul 29, 2024

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 rbri self-assigned this Aug 1, 2024
@rbri
Copy link
Member

rbri commented Aug 1, 2024

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

@hammondreg
Copy link
Author

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
Copy link
Member

rbri commented Aug 2, 2024

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

@rbri
Copy link
Member

rbri commented Aug 2, 2024

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
Copy link
Author

I am waiting with bated breath! =:-]

@rbri
Copy link
Member

rbri commented Aug 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants