如何在 C# 中使用 Selenium 刷新网页?

How can I refresh a web page with Selenium in c#?

I don't know how to fix the error, can somebody help?

如果我没记错的话应该是,我已经有一段时间没接触硒了。

driver.Navigate().Refresh();

我搜索了一下,来自 Whosebug 的 post 似乎支持这一点。

这是一个issue with chrome web driver,没有刷新。如果没有,您需要下载 chrome 网络驱动程序,否则您的环境 PATH 变量可能有问题。

也许这可以帮助你:

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using Serilog;
using System.IO;
using System.Reflection;

namespace Whosebug.Answer.Selenium.RefreshPage
{
    class RefreshPage
    {
        public static IWebDriver driver;      

        [Test]
        [Category("RefreshPage")]
        public void RefreshPageTest()
        {
            Log.Information("Get instance Chrome Browser");
            driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), OptionsChrome());

            Log.Information("Acess your url site");
            driver.Navigate().GoToUrl("http://YourUrlSite/index.aspx");

            Log.Information("Refresh page command");
            driver.Navigate().Refresh();
        }      

        private ChromeOptions OptionsChrome()
        {
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.AddArgument("--start-maximized");
            chromeOptions.AddArguments("--disable-infobars");
            chromeOptions.AddArguments("--disable-notifications");
            return chromeOptions;
        }
    }
}