1

I'm trying to write a Javascript test script. I'm unsure how I can reference and use the JavascriptExecutor in an Javascript file. How do I reference / instantiate it in Javascript? I'm using FF. Any sample code would be appreciated. thx

0

1 Answer 1

1

Just insert your JavaScript code inside the tests, you don't need JavaScriptExecutor for that.

Actually, JavaScriptExecutor is used to run JavaScript inside the browsers by WebDriver in Java environment as Java is a server side language and do not deal directly with browsers. This is done using the executeScript and executeAsyncScript methods.

Same thing is implemented in C# using IJavaScriptExecutor.

Edit:

To scroll to an ID, you can use one of the below code directly in your tests:

window.scroll(horizontalOffset, verticalOffset);

window.location.hash = '#ID';

document.getElementById('ID').scrollIntoView(true);

var divPosition = $('#divId').offset();
$('html, body').animate({scrollTop: divPosition.top}, "slow");
Sign up to request clarification or add additional context in comments.

8 Comments

I need the feature to scroll to an ID. That is not visible.
I think the only way to do that is with the JavaScriptExecutor?
The only way to do that in Java/C# is JavaScriptExecutor, but in Javascript just write the script in the test itself.
I get window not defined
window.scroll(horizontalOffset, verticalOffset);
|

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.