首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在selenium ide中使用If命令?

如何在selenium ide中使用If命令?
EN

Stack Overflow用户
提问于 2018-10-13 10:26:34
回答 1查看 9.5K关注 0票数 8

我在网上搜索了很长一段时间。我正在尝试将ifelse语句放入selenium IDE中。程序本身不提供任何参数、提示或帮助。我在网上看到了很多结果,其中只有java代码,但我不认为在这里输入代码是可行的。

谁能给我举一个如何使用if和then语句的例子?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-14 06:55:19

Basic if条件示例:

示例.side文件。将以下代码保存在名为'Test.side‘的文件中,并在selenium ide中打开

代码语言:javascript
复制
{
  "id": "92a8cfe0-a7ed-45a4-82c2-59f889cba0a6",
  "version": "1.1",
  "name": "test",
  "url": "",
  "tests": [{
    "id": "f78b739a-886c-4842-9d61-f83700ef29f6",
    "name": "test",
    "commands": [{
      "id": "ff43b0cf-7207-4599-8f11-3f90102cd1e2",
      "comment": "",
      "command": "open",
      "target": "https://in.yahoo.com",
      "targets": [],
      "value": ""
    }, {
      "id": "12efa973-069b-4254-9813-868d4a34876d",
      "comment": "",
      "command": "storeTitle",
      "target": "",
      "targets": [],
      "value": "title"
    }, {
      "id": "abde904f-6f3f-4a5a-b24a-59c3b2eafe2c",
      "comment": "",
      "command": "if",
      "target": "${title} != 'Google'",
      "targets": [],
      "value": ""
    }, {
      "id": "bb6640f2-6356-439f-b226-287030e8fa5a",
      "comment": "",
      "command": "open",
      "target": "https://www.google.com",
      "targets": [],
      "value": ""
    }, {
      "id": "ee3b8144-4981-460d-b707-e925e52ebe41",
      "comment": "",
      "command": "assertTitle",
      "target": "Google",
      "targets": [],
      "value": ""
    }, {
      "id": "f73c9836-4944-45aa-be07-9647991ffb36",
      "comment": "",
      "command": "end",
      "target": "",
      "targets": [],
      "value": ""
    }, {
      "id": "bcc2bd2b-5091-4b40-b499-f89c38e532bf",
      "comment": "",
      "command": "sendKeys",
      "target": "name=q",
      "targets": [],
      "value": "Hello world"
    }]
  }],
  "suites": [{
    "id": "e966e7ba-8ccd-418a-80e7-f99ac6c25f90",
    "name": "Default Suite",
    "persistSession": false,
    "parallel": false,
    "timeout": 300,
    "tests": ["f78b739a-886c-4842-9d61-f83700ef29f6"]
  }],
  "urls": [],
  "plugins": []
}

If with else示例

示例.side文件。

代码语言:javascript
复制
{
  "id": "92a8cfe0-a7ed-45a4-82c2-59f889cba0a6",
  "version": "1.1",
  "name": "test",
  "url": "",
  "tests": [{
    "id": "f78b739a-886c-4842-9d61-f83700ef29f6",
    "name": "test",
    "commands": [{
      "id": "ff43b0cf-7207-4599-8f11-3f90102cd1e2",
      "comment": "",
      "command": "open",
      "target": "https://www.google.com",
      "targets": [],
      "value": ""
    }, {
      "id": "12efa973-069b-4254-9813-868d4a34876d",
      "comment": "",
      "command": "storeTitle",
      "target": "",
      "targets": [],
      "value": "title"
    }, {
      "id": "abde904f-6f3f-4a5a-b24a-59c3b2eafe2c",
      "comment": "",
      "command": "if",
      "target": "${title} == 'Google'",
      "targets": [],
      "value": ""
    }, {
      "id": "bb6640f2-6356-439f-b226-287030e8fa5a",
      "comment": "",
      "command": "echo",
      "target": "I am in Yahoo Page",
      "targets": [],
      "value": ""
    }, {
      "id": "ee3b8144-4981-460d-b707-e925e52ebe41",
      "comment": "",
      "command": "assertTitle",
      "target": "Google",
      "targets": [],
      "value": ""
    }, {
      "id": "f73c9836-4944-45aa-be07-9647991ffb36",
      "comment": "",
      "command": "else",
      "target": "",
      "targets": [],
      "value": ""
    }, {
      "id": "a90e7c75-911a-46cb-ac52-a3fd394e6dfe",
      "comment": "",
      "command": "echo",
      "target": "I am in already in google Page",
      "targets": [],
      "value": ""
    }, {
      "id": "2b29d6fe-a670-4349-be18-794e85fbd498",
      "comment": "",
      "command": "end",
      "target": "",
      "targets": [],
      "value": ""
    }, {
      "id": "7f8ee438-4dae-4f34-b4b6-7a4a166acabf",
      "comment": "",
      "command": "sendKeys",
      "target": "q=name",
      "targets": [],
      "value": ""
    }]
  }],
  "suites": [{
    "id": "e966e7ba-8ccd-418a-80e7-f99ac6c25f90",
    "name": "Default Suite",
    "persistSession": false,
    "parallel": false,
    "timeout": 300,
    "tests": ["f78b739a-886c-4842-9d61-f83700ef29f6"]
  }],
  "urls": [],
  "plugins": []
}

带有ElseIf的If示例

selenium ide测试文件示例(.side)

代码语言:javascript
复制
{
  "id": "92a8cfe0-a7ed-45a4-82c2-59f889cba0a6",
  "version": "1.1",
  "name": "test",
  "url": "",
  "tests": [{
    "id": "f78b739a-886c-4842-9d61-f83700ef29f6",
    "name": "test",
    "commands": [{
      "id": "ff43b0cf-7207-4599-8f11-3f90102cd1e2",
      "comment": "",
      "command": "open",
      "target": "https://www.google.com",
      "targets": [],
      "value": ""
    }, {
      "id": "12efa973-069b-4254-9813-868d4a34876d",
      "comment": "",
      "command": "storeTitle",
      "target": "",
      "targets": [],
      "value": "title"
    }, {
      "id": "abde904f-6f3f-4a5a-b24a-59c3b2eafe2c",
      "comment": "",
      "command": "if",
      "target": "${title} == 'Google'",
      "targets": [],
      "value": ""
    }, {
      "id": "bb6640f2-6356-439f-b226-287030e8fa5a",
      "comment": "",
      "command": "echo",
      "target": "I am in Yahoo Page",
      "targets": [],
      "value": ""
    }, {
      "id": "ee3b8144-4981-460d-b707-e925e52ebe41",
      "comment": "",
      "command": "assertTitle",
      "target": "Google",
      "targets": [],
      "value": ""
    }, {
      "id": "f73c9836-4944-45aa-be07-9647991ffb36",
      "comment": "",
      "command": "elseIf",
      "target": "${title} != 'Yahoo'",
      "targets": [],
      "value": ""
    }, {
      "id": "a90e7c75-911a-46cb-ac52-a3fd394e6dfe",
      "comment": "",
      "command": "echo",
      "target": "I am in google Page",
      "targets": [],
      "value": ""
    }, {
      "id": "2b29d6fe-a670-4349-be18-794e85fbd498",
      "comment": "",
      "command": "end",
      "target": "",
      "targets": [],
      "value": ""
    }, {
      "id": "bcc2bd2b-5091-4b40-b499-f89c38e532bf",
      "comment": "",
      "command": "echo",
      "target": "I am out side the if condition",
      "targets": [],
      "value": ""
    }]
  }],
  "suites": [{
    "id": "e966e7ba-8ccd-418a-80e7-f99ac6c25f90",
    "name": "Default Suite",
    "persistSession": false,
    "parallel": false,
    "timeout": 300,
    "tests": ["f78b739a-886c-4842-9d61-f83700ef29f6"]
  }],
  "urls": [],
  "plugins": []
}
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52788965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档