最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

NEW Selenium IDE - how to run and store JavaScript? - Stack Overflow

programmeradmin3浏览0评论

I have a bunch of old test scripts that were written for the old Selenium IDE. I'm trying to update them to run with the new Selenium, but I'm having a really hard time figuring out what to do with bits of javascript and the new syntax.

For example, I have something like:

(mand)STORE (Target) javascript{Math.floor(Math.random()*100000)} (Value) ReportNumber

But all Selenium does is store the javascript expression as a variable if I use that old Syntax. I saw that the new IDE wants us to instead use Run Script but I need to run the javascript and save it as a variable and none of the attempts I've made thus far have worked. Has anyone figure out HOW to use and run javascript successfully, and to save it as a variable. Examples if you have them, please!!

I have a bunch of old test scripts that were written for the old Selenium IDE. I'm trying to update them to run with the new Selenium, but I'm having a really hard time figuring out what to do with bits of javascript and the new syntax.

For example, I have something like:

(mand)STORE (Target) javascript{Math.floor(Math.random()*100000)} (Value) ReportNumber

But all Selenium does is store the javascript expression as a variable if I use that old Syntax. I saw that the new IDE wants us to instead use Run Script but I need to run the javascript and save it as a variable and none of the attempts I've made thus far have worked. Has anyone figure out HOW to use and run javascript successfully, and to save it as a variable. Examples if you have them, please!!

Share Improve this question edited Jul 30, 2020 at 14:28 Swaroop Humane 1,8461 gold badge8 silver badges19 bronze badges asked Jul 28, 2020 at 18:04 Kathy AndersonKathy Anderson 331 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You now need to use the execute script mand instead, like this:

execute script | return Math.floor(Math.random()*100000) | ReportNumber

The "target" of the execute script mand is the JavaScript to execute, and the "value" is the name of variable you want Selenium to put the result into. The return in the JavaScript is not optional!

发布评论

评论列表(0)

  1. 暂无评论