【问题标题】:C# Selenium - Unable to get background color of element mouse is hovering overC# Selenium - 无法获取元素鼠标悬停的背景颜色
【发布时间】:2019-03-10 00:41:20
【问题描述】:

我在我的方法中这样做:

var firstCategoryTitle = pageTypeCategoryDiv.FindElement(By.ClassName("result.firstCategory")); // this is definitely selecting the correct element

Actions action = new Actions(Driver);
            action.MoveToElement(firstCategoryTitle).Click().Build().Perform();

            firstCategoryTitle.GetCssValue("background-color").Should().Be("rgba(0, 155, 212, 1)");

由于某种原因,即使当鼠标单击行元素时它被突出显示,背景颜色也会变为蓝色(如预期的那样),但是一旦测试完成运行它就会抛出错误,因为它找不到预期的颜色(预期的蓝色)并始终找到白色,即使元素将突出显示为蓝色。

感谢任何帮助。

【问题讨论】:

  • 在 Chrome 中,打开 Developer Tools > Elements 选项卡,找到您的元素并在右侧选择 Computed。它有什么价值?您所看到的很可能是 Selenium 将返回的内容。也请贴出相关的HTML代码

标签: c# selenium action mouseover mousehover


【解决方案1】:

添加一个延迟,只是为了检查在实际颜色变化之前是否没有执行GetCssValue语句。

        Actions action = new Actions(Driver);
        action.MoveToElement(firstCategoryTitle).Click().Build().Perform();
        Thread.Sleep(5000);
        firstCategoryTitle.GetCssValue("background-color").Should().Be("rgba(0, 155, 212, 1)");

【讨论】:

    猜你喜欢
    • 2013-05-29
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 2017-10-24
    相关资源
    最近更新 更多