Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查C中的按钮颜色#_C#_Selenium Webdriver - Fatal编程技术网

C# 检查C中的按钮颜色#

C# 检查C中的按钮颜色#,c#,selenium-webdriver,C#,Selenium Webdriver,我编写了以下函数,用C#selenium web驱动程序验证按钮颜色,但它返回false,不知道问题出在哪里: public Boolean check_source_button_color() { Boolean Cond1 = false; try { String headerColor = driver.FindElement(By.XPath("//div[13]/div/a")) .GetCssValue("back

我编写了以下函数,用C#selenium web驱动程序验证按钮颜色,但它返回
false
,不知道问题出在哪里:

public Boolean check_source_button_color()
{
    Boolean Cond1 = false;

    try
    {
        String headerColor = driver.FindElement(By.XPath("//div[13]/div/a"))
            .GetCssValue("background-color");

        if (Assert.Equals("#15688f", headerColor))    
        {
            Cond1 = true;
        }
    }
    catch { };

    return Cond1;
}
在这个问题上我称之为

if (Req_det_page.check_source_button_color())
{
    Cond3 = true;
}

Cond3总是错误的

这是编辑后的代码,它运行良好

   public Boolean check_source_button_color()
        {
            Boolean Cond1 = false;
            try
            {
                string headerColor = (driver.FindElement(By.LinkText("Go to regulatory source website")).GetCssValue("background-color"));

                String[] hexValue = headerColor.Replace("rgba(", "").Replace(")", "").Split(',');

                hexValue[0] = hexValue[0].Trim();

                int hexValue1 = int.Parse(hexValue[0]);

                hexValue[1] = hexValue[1].Trim();

                int hexValue2 = int.Parse(hexValue[1]);

                hexValue[2]  = hexValue[2].Trim();

                int hexValue3 = int.Parse(hexValue[2]);

                hexValue[3] = hexValue[3].Trim();

                int hexValue4 = int.Parse(hexValue[3]);

                String actualColor = String.Format("#{0:X2}{1:X2}{2:X2}", hexValue1, hexValue2, hexValue3);

                Console.WriteLine( headerColor);
                Console.WriteLine("actualColor is " + actualColor);

                if (actualColor.Equals("#1e95ce"))
                {
                    Cond1 = true;
                }

                }
            catch (System.Exception ex )
            {
                Console.WriteLine(ex.Message);
            }
            return Cond1;
        }

我认为您的代码可能会跳转到catch子句。你介意分享一下stacktrace吗?这将为您的问题提供线索,并指导我们帮助您在调试程序中单步执行代码时会发生什么情况?在捕获中放入异常消息后,我发现字符串格式存在问题,并且标题颜色为rgba值,因此与十六进制值的比较为false。因此,我搜索了一个函数,将rgba转换为十六进制值,并对代码进行了一些更改,最后它成功了。