C# 硒 - 无法获取元素鼠标悬停的背景颜色



我在我的方法中这样做:

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)");

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

任何帮助都值得赞赏。

添加延迟,只是为了检查在实际颜色更改之前是否未执行 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)");

最新更新