-1

I'm truing to execute a yui js script with js.executeScript Selenium's method. The script is being executed by selenium webdriver in order simulate a "click" on hybrid mobile app (the button is webview)

 String IncludeYUI = "script = document.createElement('script');script.type = 'text/javascript';script.async = true;script.onload = function(){};script.src = '"
                    + YUI_PATH
                    + "';document.getElementsByTagName('head')[0].appendChild(script);";
            js.executeScript(IncludeYUI);

where the YUI_PATH is an url - https://cdnjs.cloudflare.com/ajax/libs/yui/3.18.0/yui/.....

The problem is that I do not have an access to the global network from the current site.

so I was thinking to save the script under the project and just to load it from FS. But this is a js , no access to the FS ...

Any ideas how to load the script ?

Thanks

9
  • How are you loading the page to start? Commented Apr 20, 2015 at 12:59
  • I dont have a page to start , just executing js code in order to click on some webElement Commented Apr 20, 2015 at 13:49
  • You could copy paste the whole textual content of your library with all newlines removed as an literal to a String s that you execute with js.executeScript(s). After that your library should be available. Commented Apr 20, 2015 at 19:03
  • @halex - Thanks for your answer , could you please explain about "with all newlines removed as an literal" ? Commented Apr 27, 2015 at 8:45
  • @Igal Remove all occurrences of newlines in your library (like you want to minimize it) to get the source as one big string. This only works if all statements are properly terminated with ; otherwise you would need to walk through the library's code and bring it into a form that you can use as one big line by hand. Commented Apr 27, 2015 at 10:32

2 Answers 2

0

So, you're loading an html page somewhere, right? Conceptually you would load your JS file the same way: you make a request to your server to load the JS file, just like you did to load your html page.

That would look like this:

<script src="scripts/yourFile.js">

Also, I've never seen anyone loading a js file like you're doing in your code sample...I would most definitely just recommend putting a script tag in your html.

You may want to post your html code as well; we'll be able to provide better help. I'll update this answer accordingly if needed.

Sign up to request clarification or add additional context in comments.

8 Comments

There is no HTML code. The main Idea is to click on webelement on hybrid mobile app. The 'js' is a JavascriptExecutor which comes with selenium package
eventually the executed code looks as the following (log file): --> POST /wd/hub/session/fd19efd9-1365-4a2d-9613-19a19b4d518f/execute {"script":"script = document.createElement('script');script.type = 'text/javascript';script.async = true;script.onload = function(){};script.src = 'yui-min.js';document.getElementsByTagName('head')[0].appendChild(script);","args":[]}
Ok, I'm sort of lost then. So you're using selenium...and you're loading JS into your selenium-created browser session? So you're injecting code into an existing html page? You may want to try and explain the full problem more in your original question. It's very much possible to load a JS file from a local server somewhere behind your firewall/DMZ/whatever if you can't hit the outside world, but without a better idea of what you're trying to accomplish, we might not be able to help you much.
'in order simulate a "click" on hybrid mobile app' -- This isn't quite right. You're injecting the YUI library into the page. And I still can't understand why... Whatever site you're testing has its own responsibility of importing the JS file, not your selenium code. Your selenium code is injecting the download of a JS file into the head of that html page. Let's back up for a second: what JS is the site currently pulling in already? How about images, or css? If you can find that out, you can keep a local copy and put it in the same general location and we can go from there...
Better yet, load the html page yourself in a browser. Then paste the current <head> section in your original question for me please.
|
0

Finally , after many tries , some1 has suggested me to work with jquery. after some digging , I've used executeScript with jquery's tap , and it worked...

$('#btn_login_button').trigger('tap');

I was wondering all other methods with click and element's coordinates didn't work

Comments

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.