Selenium 简明教程

Selenium - User Extensions

通过添加自定义操作、断言和定位器策略,可以轻松扩展 Selenium IDE。通过将方法添加到 Selenium 对象原型中,借助 JavaScript 来完成此操作。在启动时,Selenium 会自动通过这些原型查看方法,使用名称模式来识别哪些是操作、断言和定位器。

It is easy to extend Selenium IDE by adding customized actions, assertions, and locator-strategies. It is done with the help of JavaScript by adding methods to the Selenium object prototype. On startup, Selenium will automatically look through the methods on these prototypes, using name patterns to recognize which ones are actions, assertions, and locators.

让我们借助 JavaScript 在 Selenium IDE 中添加一个“while”循环。

Let us add a 'while' Loop in Selenium IDE with the help of JavaScript.

Step 1 ——要添加 js 文件,首先导航至 https://github.com/darrenderidder/sideflow/blob/master/sideflow.js 并复制脚本并将其保存在本地文件夹中,如下所示:“sideflow.js”。

Step 1 − To add the js file, first navigate to https://github.com/darrenderidder/sideflow/blob/master/sideflow.js and copy the script and place save it as 'sideflow.js' in your local folder as shown below.

selenium ide 24

Step 2 ——现在启动“Selenium IDE”并导航至“Options”>>“Options”,如下所示。

Step 2 − Now launch 'Selenium IDE' and navigate to "Options" >> "Options" as shown below.

selenium ide 25

Step 3 ——在“Selenium Core Extensions”区域下单击“Browse”按钮,并指向我们在步骤 1 中保存的 js 文件。

Step 3 − Click the 'Browse' button under 'Selenium Core Extensions' area and point to the js file that we have saved in Step 1.

selenium ide 26

Step 4 ——重新启动 Selenium IDE。

Step 4 − Restart Selenium IDE.

Step 5 ——现在你将可以访问更多命令,例如“Label”、“While”等。

Step 5 − Now you will have access to a few more commands such as "Label", "While" etc.

Step 6 ——现在,我们将在 Selenium IDE 中创建 While 循环,它将按如下所示执行。

Step 6 − Now we will be able to create a While loop within Selenium IDE and it will execute as shown below.

selenium ide 27