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

Is it possible to ExecuteJavaScript or emulate user actions like key pressing on loaded page? #183

Closed
ziomyslaw opened this issue Nov 14, 2018 · 9 comments

Comments

@ziomyslaw
Copy link

I am looking for solution to replace NightmareJs with c# implementation.
The NightmareJs wraps electron api to allows not only to type or click but execute js as well i.e.
win.webContents.executeJavaScript(src)
WebContents does not provide such methods.
Is there any equivalent way to do this?

@kwakuduahc1
Copy link

Are you using an SPA framework or not?

@ziomyslaw
Copy link
Author

I used to use NightmareJs + MeteorJs, but I'm looking for c# solution. Something faster than Selenium+Chrome.

@GregorBiswanger
Copy link
Member

@ziomyslaw you can use https://electronjs.org/spectron

For .NET Support write a Spectron.NET solution for Electron.NET :)

@niklr
Copy link

niklr commented Feb 24, 2019

I think what he means is similar to this question: https://stackoverflow.com/questions/28920621/how-to-call-a-javascript-function-on-a-web-page-rendered-by-electron

What is the equivalent to the following solution in Electron.NET?

app.on('ready', function() {

  ...

  mainWindow.webContents.on('did-finish-load', function() {
    mainWindow.webContents.executeJavaScript("alert('Hello There!');");
  });

  ...

});

@LittleEndu
Copy link

Is there any solution to this? Being able to execute javascript and to convert the resulting javascript object into a C# object would be very useful.

@GregorBiswanger
Copy link
Member

@LittleEndu yes, that works with the ElectronHost Hook feature. Take a look at the example of the WebApp here. There is a sample code deposited. In the example application you can also get a step by step guide.

@MrCircuit
Copy link

I managed to inject the "electron-chromedriver" npm package into the build command of ElectronNET. It was simply by adding another line after npm install at line 123 in BuildCommand.cs:

            ProcessHelper.CmdExecute("npm install electron-chromedriver", tempPath);

Of course, this could also be achieved by editing the packages.json file.

Using this modified build command, I built the whole ElectronNet project. Then created a small .NET test project with ChromeDriver that uses the "BinaryLocation" property at driver creation. With this setup, I can control and test the ElectronNET application.

@vleeuwenmenno
Copy link

I am trying to execute some JS code as well, but so far I have not found any solution. I am in need of the executeJavaScript(string) function.

@windhuan
Copy link

i used LoadURL to exec javascript .

            browserWindow.WebContents.OnDidFinishLoad += () =>
            {
                browserWindow.LoadURL("javascript:alert('111')");
            };

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

No branches or pull requests

8 participants