【问题标题】:FindsBy from SeleniumExtras can't find IWebElement来自 SeleniumExtras 的 FindsBy 找不到 IWebElement
【发布时间】:2018-10-17 06:44:33
【问题描述】:

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

【问题讨论】:

    标签: c# selenium selenium-webdriver pageobjects


    【解决方案1】:

    解决办法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多