【问题标题】:How to use AND condition in Robot Framework?如何在 Robot Framework 中使用 AND 条件?
【发布时间】:2018-04-12 16:28:42
【问题描述】:

我的 HTML 内容如下:

<input type="radio" name="radioButton" value="on" id="radio1" tabindex="0">
<input type="radio" name="radioButton" value="on" id="radio2" tabindex="0">
<input type="radio" name="radioButton" value="on" id="radio3" tabindex="0">

参考: How to use OR condition for Keywords in Robot Framework?

我目前正在尝试上面链接中提到的逻辑。但这与我的场景不是最相关的。

我想使用它的类型、名称和 id 或类来获取并选择单选按钮。

我想实现以下目标:

选择单选按钮如果 //input[@type="radio"] AND //input[name="radioButton"] AND //input[@id="radio2"]

【问题讨论】:

    标签: selenium robotframework


    【解决方案1】:

    您不需要if 声明。只需将所有条件放在一个 xpath 中。例如:

    select radio button  //input[@type='radio' and @name='radioButton' and @id='radio2']
    

    不过,如果 id 是唯一的,那么您就不需要所有这些。如果 id 是唯一的,您可以使用类似:

    select radio button //input[@id='radio2']
    

    【讨论】:

      【解决方案2】:

      你可以做下一个

      WebDriver driver = new FirefoxDriver(); //it can be any driver, not specifically firefox
      
      WebElement radioButton = driver.findElement(By.xpath("//input[@type='radio' and @name='radioButton' and @id='radio2']");
      radioButton.click();
      

      上面的函数会寻找元素并点击它。正如@Bryan 所说,如果 id 是唯一的,您只能通过其 id 查找元素。

      WebDriver driver = new FirefoxDriver(); //it can be any driver, not specifically firefox
      WebElement radioButton = driver.findElement(By.id("@id='radio2']");
      radioButton.click();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-10
        • 2019-08-26
        • 2017-12-31
        • 1970-01-01
        • 1970-01-01
        • 2012-10-06
        • 2013-06-06
        • 1970-01-01
        相关资源
        最近更新 更多