简体   繁体   中英

Call JavaScript function from Selenium Web IDE

I've this global function in my site

function formatDate(_date) {
    return _date.getFullYear() + '/' + (_date.getMonth() + 1) + '/' + _date.getDate();
}

When I try to use it in the IDE with the following command

<tr>
    <td>type</td>
    <td>id=comments</td>
    <td>javascript{"e2e-" + formatDate(new Date())}</td>
</tr>

and I run the test then the IDE stay in that command forever but do not execute it.

What I'm doing wrong?

I have a similar function in one of my scripts and found that they way to do it is to break it down into 2 parts. Execute the function and store it as a variable, and then use the variable for your command. eg

My function is named:

function getddmmyyyy() 

then in selenium I have a command to execute the javascript and store it

<tr>
    <td>storeEval</td>
    <td>getddmmyyyy</td>
    <td>date</td>
</tr>

and then for the command it is:

<tr>
    <td>click</td>
    <td>css=[value="${date}"]</td>
    <td></td>
</tr>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM