c# - 如何只运行一次浏览器
问题描述
我只想启动一次浏览器,然后从那里获取非静态信息。但是我的浏览器启动了很多次。当我的 bool = false 时,我怎样才能只启动一次并关闭它;
class Program
{
public static bool GameIsRun = true;
static void Main(string[] args)
{
CheckGame();
}
public static ChromeDriver GetDriver()
{
return new ChromeDriver();
}
public static void CheckGame()
{
while (GameIsRun)
{
GetInformation(GetDriver());
}
}
static void GetInformation(ChromeDriver driver)
{
driver.Navigate().GoToUrl("myURL");
do
{
//loop for doing something on this page, I don't want to start my browser many times.
}
while ();
}
}
解决方案
愿这对你有用。
class Program
{
public static bool GameIsRun = true;
public static IWebDriver driver = null;
static void Main(string[] args)
{
CheckGame();
}
public static ChromeDriver GetDriver()
{
if(driver == null){
driver = new ChromeDriver();
}
return driver;
}
public static void CheckGame()
{
while (GameIsRun)
{
GetInformation(GetDriver());
}
}
static void GetInformation(ChromeDriver driver)
{
driver.Navigate().GoToUrl("myURL");
do
{
//loop for doing something on this page, I don't want to start my browser many times.
}
while ();
}
}
推荐阅读
- reactjs - 在 React 上管理用户从游戏“房间”的退出?
- php - 为什么在我从 PHP 5.6 迁移到 7.3 之后,函数“session_regenerate_id”停止工作?
- javascript - 通过字符串从对象数组和子对象数组中获取动态值
- php - 如果您在另一个文件夹中有 index.php,如何在主页中设置它?
- c# - 无法从 GET 响应中获取数据
- reactjs - ./node_modules/material-ui-icons/AccessAlarm.js 找不到模块:无法解析“material-ui/SvgIcon”
- azure - Azure 应用服务 - 如何禁用弱密码?
- python - 从执行进程任务 SSIS 运行 .pyw 文件
- php - 尝试将 sql 结果作为 json 数据类型回显时出现语法错误
- python - python:如何直接从字节字符串变量显示图像?