【问题标题】:How to create an if statement in selenium that would run if a certain box was not checked?如果未选中某个框,如何在 selenium 中创建将运行的 if 语句?
【发布时间】:2010-08-20 12:46:14
【问题描述】:

我正在尝试在 selenium 中运行 if 语句,该语句将验证是否选中了复选框以及是否未执行特定操作。我试过了

if (selenium.verifyChecked("checkbox")=false){
//perform actions
} else {
//perform different actions
};

它说那不起作用。你会怎么做?

【问题讨论】:

    标签: selenium automated-tests


    【解决方案1】:

    Selenium 命令isChecked 返回一个布尔值,因此您应该能够执行以下操作:

    if (selenium.isChecked("checked")) {
      //perform actions
    } else {
      //perform different actions
    };
    

    【讨论】:

    • 谢谢。这就是我发现并最终使用的。比 try 好多了 - catch 和 verifyChecked();
    【解决方案2】:
    if (selenium.verifyChecked("checkbox")=false){
    

    错了。将函数的返回值赋值为 false,这显然是错误的。

    应该是:

    if (selenium.verifyChecked("checkbox") == false) {
    

    【讨论】:

    • 好吧,这也行不通:if (!selenium.verifyChecked("checkbox")) {
    猜你喜欢
    • 1970-01-01
    • 2011-04-02
    • 2021-12-06
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多