I am trying to understand the meaning of the following declaration:

JavascriptExecutor js = (JavascriptExecutor) driver; 

I know that the left side means to create an identifier js with type as JavascriptExecutor, but I am unable to understand what the right-hand syntax means

I read like JavascriptExecutor is an interface and that interfaces cannot be initialized. So what does the code actually does here

closed as off-topic by Rsf, Nitin Rastogi, Bharat Mane, IAmMilinPatel, Ray Oei Jun 25 at 22:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development unrelated to testing are off-topic here, but can be asked on Stack Overflow." – Rsf, Nitin Rastogi, Bharat Mane, IAmMilinPatel, Ray Oei
If this question can be reworded to fit the rules in the help center, please edit the question.


Drivers seems implementations of JavascriptExecutor. So it can be type casting.

https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html . You could read more about this at the mentioned link

enter image description here

  • 1
    @PDHide Thank you for your editing. – junghan Jun 27 at 7:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.