how to call .js from webdriver selenium

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

how to call .js from webdriver selenium

Illusion0Reality
I have one .js file on "c:/popup.js"
---
function popup()
{
alert("Hello World")
}
-----------------------------


I called in 2 ways from webdriver like below:

selenium.getEval("popup.js");
and---------------
((JavascriptExecutor)driver).executeScript("c:/popup.js");

Problem could be with syntax ONLY

Error:
(JavaScript error (WARNING: The server did not provide any stacktrace information); d)
Reply | Threaded
Open this post in threaded view
|

Re: how to call .js from webdriver selenium

softwaretestingforum
Administrator
In Java script executor, executeScript should be passes the js it self,  but in your case - "c:/popup.js" is not js but the location of file js is stored.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: how to call .js from webdriver selenium

Illusion0Reality
thanks for the reply Tarun.
Let us ignore the 2nd way.
What would be the issue with the 1st way, please let me know.
Reply | Threaded
Open this post in threaded view
|

Re: how to call .js from webdriver selenium

softwaretestingforum
Administrator
It's the same issue with getEval also. It expects you to pass it actual js but you passed the location of your js file.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: how to call .js from webdriver selenium

illusion0reality
Thanks Tarun!

So, at least upto our knowledge, should I assume that, we can't pass .JS file with getEval as a parameter.

Is the .JS used very frequently with SElenium for the day-to-day operations (normal I mean), not for a specific purpose.
I meant, enter text, select checkbox etc, webtable interaction - we don't need .JS.

Is my assumption correct.
Reply | Threaded
Open this post in threaded view
|

Re: how to call .js from webdriver selenium

softwaretestingforum
Administrator
Yup you don't need for day to day operations. It's only for those times when for some strange reason you would not be able to exercise some html element. Then js execution would come for rescue .
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: how to call .js from webdriver selenium

Illusion0Reality
Thanks Tarun!

Good information for me.