【问题标题】:In my application, i need to validate Pass or Fail icon in Selenium webdriver在我的应用程序中,我需要验证 Selenium webdriver 中的通过或失败图标
【发布时间】:2016-08-22 10:55:02
【问题描述】:

这是应用程序上的 html

 div id="StatusCircle" style="float: right; width: 50px; height: 50px;-webkit-border-radius: 25px;-moz-border-radius: 25px;border-radius: 25px;background: RED;" - this is for Fail

 div id="StatusCircle" style="float: right; width: 50px; height: 50px;-webkit-border-radius: 25px;-moz-border-radius: 25px;border-radius: 25px;background: GREEN;" - this is for Pass

我可以得到

  .//*[@id='MainContent']/a[2]/div/div/div[@id='StatusCircle']

但是如何获得它的红色或绿色。

【问题讨论】:

  • 您可以使用 selenium 验证属性,获取属性背景颜色的值,以便将其验证为绿色通过,失败为红色
  • 旁白:为什么你有一个有两个 id 的 xpath?只需 id StatusCircle 就足够了,因为 id 应该是唯一的

标签: html css selenium


【解决方案1】:

您需要使用返回 rgb 值的“getCssValue()”获取颜色背景,然后转换为十六进制值进行检查。

更多信息:

getCssValue (Color) in Hex format in Selenium WebDriver

Selenium Webdriver - Get Background color of an element in Hex - Example

【讨论】:

    【解决方案2】:
    IWebElement statusElement = driver.FindElement(By....);
    string statusAttribute = statusElement.GetAttribute("style");
    if (statusAttribute.Contains("RED"))
    {
      //Status is Fail
    }
    else if (statusAttribute.Contains("GREEN"))
    {
        //Status is Fail
    }
    

    【讨论】:

      猜你喜欢
      • 2011-06-15
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多