简体   繁体   中英

Execute JavaScript in browser using Selenium + JavaScript or WebDriverJS

After whole lot of search for many days I am asking for help here.

We have a setup where we are using javascript + selenium(webdriverjs).

We want to pass data in the browser which is opened via selenium. putting it simply, we want to execute any kind of javascript in the browser.

In java+selenium, we have JavaScriptExecutor class which does this thing. In javascript+selenium I am not able to find any thing similar to it.

I have experimented with driver.executeJavaScript and driver.executeScript. But that does not work.

Please help.

Note: I can't use protractor in my project.

here you go an example protractor

browser.executeScript('window.scrollTo(0,0);');

async execution

browser.executeAsyncScript('window.scrollTo(0,0);');

for webdriver js or other framework try with

driver.executeScript()

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