SeleniumExtras 的 FindsBy 找不到 IWebElement

FindsBy from SeleniumExtras can't find IWebElement

我已经更新了我在 Mac 上的项目的包,发现 PageObjects 已移至 SeleniumExtras。我很难使用它,但显示 错误 "System.NullReferenceException : Object reference not set to an instance of an object."。 尽管如此,可以通过 FindElement 找到相同的元素。目前,我 运行 没有想法,希望得到帮助。 谢谢!

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();
        }
    }
}

得到解决方案:

  1. 通过 NuGet 包添加所有 DotNetSeleniumExtras:PageObjects 和 PageObjects.Core;
  2. 添加命名空间: 使用 FindsByAttribute = SeleniumExtras.PageObjects.FindsByAttribute; 如何使用 = SeleniumExtras.PageObjects.How;