C# SeleniumExtras的FindsBy可以';找不到IWebElement

C# SeleniumExtras的FindsBy可以';找不到IWebElement,c#,selenium,selenium-webdriver,pageobjects,C#,Selenium,Selenium Webdriver,Pageobjects,我已经在Mac上更新了我的项目包,并发现PageObjects已被移动到SeleniumExtras。我很难使用它,但显示了错误“System.NullReferenceException:对象引用未设置为对象的实例。”。 然而,通过FindElement可以找到相同的元素。目前,我没有想法了,希望能得到帮助。 谢谢 获得解决方案: 通过NuGet包添加所有DotNetSeleniumExtras:PageObjects和PageObjects.Core 添加名称空间: 使用FindsByAtt

我已经在Mac上更新了我的项目包,并发现PageObjects已被移动到SeleniumExtras。我很难使用它,但显示了错误“System.NullReferenceException:对象引用未设置为对象的实例。”。 然而,通过FindElement可以找到相同的元素。目前,我没有想法了,希望能得到帮助。 谢谢

获得解决方案:

  • 通过NuGet包添加所有DotNetSeleniumExtras:PageObjects和PageObjects.Core
  • 添加名称空间: 使用FindsByAttribute=SeleniumExtras.PageObjects.FindsByAttribute; 使用How=SeleniumExtras.PageObjects.How 获得解决方案:

  • 通过NuGet包添加所有DotNetSeleniumExtras:PageObjects和PageObjects.Core
  • 添加名称空间: 使用FindsByAttribute=SeleniumExtras.PageObjects.FindsByAttribute; 使用How=SeleniumExtras.PageObjects.How
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using NUnit.Framework;
    using NUnit.Compatibility;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    using SeleniumExtras.PageObjects;
    
    
    namespace SomeTest
    {
        [TestFixture]
        public class UnitTest1
        {
            [FindsBy(How = How.XPath, Using = "//*[@id='lst-ib']")]
            public IWebElement _searchField;
    
            public IWebDriver chrome;
    
            [SetUp]
            public void TestMethod1()
            {
                chrome = new ChromeDriver(@"/Volumes/Macintosh HD/QA/SomeTest/SomeTest/bin/Debug/netcoreapp2.1");
            }
            [Test]
            public void SomeTest()
            {
                chrome.Navigate().GoToUrl("https://www.google.com/");
                _searchField.SendKeys("Some Text");
            }
            [TearDown]
            public void CloseBrowser()
            {
                chrome.Close();
            }
        }
    }