4

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.

    1 Answer 1

    7

    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() 
    3
    • browser is available only with protractor as far as I know. I can't use protractor.
      – Pramod
      CommentedOct 12, 2018 at 9:46
    • try with driver
      – Infern0
      CommentedOct 12, 2018 at 10:12
    • ok it worked. I had tried this before. My colleague was able to see it working but I couldn't. Problem was I was executing this inside a promise and for some reason it wasn't working. const promise = driver.get('https://google.co.in/'); promise.then(function() { driver.executeScript('window.abc="pramod";'); } After I removed it from promise and moved it above promise then it started working.
      – Pramod
      CommentedOct 12, 2018 at 10:44

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.