也许这可以帮助你:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using Serilog;
using System.IO;
using System.Reflection;
namespace StackOverFlow.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;
}
}
}
这是chrome 网络驱动程序的问题,而不是刷新的问题。如果没有,您需要下载 chrome Web 驱动程序,否则您的环境 PATH 变量可能有问题。