试图获取和元素的 css 并断言这是真的,我不断收到错误

本文关键字:真的 错误 获取 元素 断言 css | 更新日期: 2023-09-27 18:36:43

我想验证网站导航栏*上的CSS,主要是颜色和位置。 以下是相关的 HTML:

<div id="MainNavigationMenu" class="header-menu">

我获取导航 CSS 的方法如下:

public string getLandingColor(){
    IWebElement getLink = driver.FindElement(By.ClassName("header-menu"));
    //checking the color = #767676
    string NavigationMenu = getLink.GetCssValue("color");
    return NavigationMenu;
}

我的测试是:

[Test, Description("Testing Landing Page and Asserting Format Check")]
public void LandingPageVerificiation() {
        Assert.AreSame("#767676", getLandingColor());       
}

NUnit 显示以下异常:

OpenQA.Selenium.NoSuchElementException : 找不到类名 == header-menu 的元素at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary'2 parameters)at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)at OpenQA.Selenium.By.FindElement(ISearchContext context)at UnitTestProject1.Browser_Landing.getLandingColor() in c:''Users''erikag''Desktop''AutomationTests''VS_NetSeleniumTest''UnitTestProject1''UnitTestProject1''Browser_Landing.cs:line 53at UnitTestProject1.ServiceConsoleTest.LandingPageVerificiation() in c:''Users''erikag''Desktop''AutomationTests''VS_NetSeleniumTest''UnitTestProject1''UnitTestProject1''TestSuite_LandLog.cs:line 39
我的

浏览器打开了,所以我知道我的测试设置和拆卸正在工作。

如何使用其类名在 HTML 中正确检索此元素,并断言 CSS 值颜色为 = 到 #767676

*网站 www.smartdrive.net,HTML示例直接来自它

试图获取和元素的 css 并断言这是真的,我不断收到错误

为了使Webdriver与IE11一起使用,我在Google论坛上发现了更多内容:

使 IE11 工作;网络驱动程序

https://code.google.com/p/selenium/wiki/InternetExplorerDriver

https://www.youtube.com/watch?v=hQFwa8OgxLM

注册表编辑器修复

  1. 仅对于 IE 11,您需要在目标计算机上设置注册表项,以便驱动程序可以保持与其创建的 Internet Explorer 实例的连接。对于 32 位 Windows 安装,必须在注册表编辑器中检查的项是 HKEY_LOCAL_MACHINE''SOFTWARE''Microsoft''Internet Explorer''Main''FeatureControl''FEATURE_BFCACHE。对于 64 位 Windows 安装,密钥是 HKEY_LOCAL_MACHINE''SOFTWARE''Wow6432Node''Microsoft''Internet Explorer''Main''FeatureControl''FEATURE_BFCACHE。请注意,FEATURE_BFCACHE子项可能存在,也可能不存在,如果不存在,则应创建。重要: 在此注册表项中,创建一个名为 iexplore.exe 的 DWORD 值,其值为 0。 摘自 IE 网络驱动程序帮助文档

  2. HKEY_LOCAL_MACHINE''软件''Wow6432Node''Microsoft''Internet Explorer''FeatureControl''FEATURE_DISABLE_INTERANL_SECURITY_MANAGER

    • 确保 iexplore.exe dword = 1
  3. HKEY_LOCAL_MACHINE''软件''Microsoft''Internet Explorer''MAIN''FeatureControl''FEATURE_DISABLE_INTERANL_SECURITY_MANAGER

    • 确保 iexplore.exe dword = 1
  4. 互联网选项>安全性,选中启用保护模式和高级>安全>取消选中启用增强保护模式