How to execute jQuery using lelenium2Library under Robot Framework

3,604 views
Skip to first unread message

許維城

unread,
Sep 4, 2013, 4:02:50 AM9/4/13
to robotframe...@googlegroups.com
I am new to robot framework,

and want simulate control the jQuery component via executing jQuery

However, the Selenium2Library almost drives me crazy.

try to get value of the DOM component but the log shows NONE.


The following is my test code.

Thanks in advance.

    click configuration
        [Tags]    xpath
        Open Browser    http://${host}    ie
        Log   "123"
        # Print Poc    "haha"
        # get_image    ${host}    S:/image/image/a.jpg
        ${slide val}=    Execute JavaScript    window.jQuery("#gain_slider_handle").val();
        ${title}=       Execute JavaScript      window.$("head title")[0];
        # ${code}=        '$("head title")[0];'
        ${t2}=          Execute JavaScript      window.eval('window.document.title')
        # Execute JavaScript    alert("hihi")
        Sleep   1s
        # Execute JavaScript    window.jQuery(alert(window.jQuery("#gain_slider_handle").val();));
        # Execute JavaScript    window.jQuery("#gain_slider_handle").val('10');
        # Execute JavaScript    window.jQuery("#gain_slider_handle").slider('refresh');
        # Execute JavaScript    window.jQuery("#exposureProfile").click()
        Log     ${slide val}
        Log     ${title}
        # Get Value From User     ${slide val}
        # Sleep    2s

Eliza

unread,
Sep 19, 2013, 2:32:09 PM9/19/13
to robotframe...@googlegroups.com

You are very close.

When you execute a javascript, the returned value is whether the call succeeded or failed, NOT the value you got from your script.
To retrieve the value, add 'return'.

${slide val}=    Execute JavaScript    return window.jQuery("#gain_slider_handle").val();

huiyua...@dianping.com

unread,
Jul 10, 2014, 11:15:32 PM7/10/14
to robotframe...@googlegroups.com
hello,I have some questions about this.

Execute Javascript return window.$("#OrderId").val("123") //I want  to set the value of OrderId by 123.but it doesn't right

David

unread,
Jul 11, 2014, 4:55:58 PM7/11/14
to robotframe...@googlegroups.com
I'm not so familiar with jQuery syntax, so if you execute the javascript in a browser dev console, like 

var result = window.$("#OrderId").val("123");
console.log(result);

do you get what you desire? It may be you need to do this:

${result}=  Execute Javascript window.$("#OrderId").val = "123"; return window.$("#OrderId").val();

not sure if you can combine assignment and returning in a single javascript statement, but logically it would be like above when thinking of normal javascript.
Reply all
Reply to author
Forward
0 new messages