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()
Sign up to request clarification or add additional context in comments.

3 Comments

browser is available only with protractor as far as I know. I can't use protractor.
try with driver
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.