Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WindowsForms应用程序-如何在后台打开网站并执行操作?_C#_Selenium_Windows Forms Designer - Fatal编程技术网

C# WindowsForms应用程序-如何在后台打开网站并执行操作?

C# WindowsForms应用程序-如何在后台打开网站并执行操作?,c#,selenium,windows-forms-designer,C#,Selenium,Windows Forms Designer,首先,谢谢你看我的问题,这意味着很多D 不久前,我用Python编写了一个Selenium脚本,用于登录网站、单击一些按钮并关闭浏览器。 这是非常低效和笨重的,所以我尝试在C#中的WindowsForms应用程序中制作一个更加用户友好的版本 问题是,我甚至不知道如何开始,我在网上找了一些人试图做同样的事情,但我找不到答案。 如何使网站在WindowsForms应用程序的后台运行,使用用户名和密码登录,单击网站中的一些按钮,然后关闭网站 我对代码有“相当”的了解,所以如果我犯了任何错误,请原谅我

首先,谢谢你看我的问题,这意味着很多D

不久前,我用Python编写了一个Selenium脚本,用于登录网站、单击一些按钮并关闭浏览器。 这是非常低效和笨重的,所以我尝试在C#中的WindowsForms应用程序中制作一个更加用户友好的版本

问题是,我甚至不知道如何开始,我在网上找了一些人试图做同样的事情,但我找不到答案。 如何使网站在WindowsForms应用程序的后台运行,使用用户名和密码登录,单击网站中的一些按钮,然后关闭网站

我对代码有“相当”的了解,所以如果我犯了任何错误,请原谅我

更新
我通过从工具箱中拖入一个web浏览器,成功地将其导入到我的应用程序中。我现在正在查看microsoft文档,以了解如何操作它。是否有一种方法可以阻止webbrowser的用户交互?

我想你可以在c#中使用selenium。使用SeleniumWeb驱动程序,您可以通过您下载的网站或HTML代码在代码中执行任何操作

有关更多信息,您可以使用,也可以查看如何实现和使用它 硒最常见的用法是端到端测试,但您可以随心所欲地进行测试

这里有一个简单的例子:

    using OpenQA.Selenium;  
using OpenQA.Selenium.Chrome;  
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading;  
using System.Threading.Tasks;  
namespace SeleniumTest  
{  
class Program  
{  
static void Main(string[] args)  
{  
Console.Write("test case started ");  
//create the reference for the browser  
IWebDriver driver = new ChromeDriver();  
// navigate to URL  
driver.Navigate().GoToUrl("https://www.google.com/");  
Thread.Sleep(2000);  
// identify the Google search text box  
IWebElement ele = driver.FindElement(By.Name("q"));  
//enter the value in the google search text box  
ele.SendKeys("javatpoint tutorials");  
Thread.Sleep(2000);  
//identify the google search button  
IWebElement ele1 = driver.FindElement(By.Name("btnK"));  
// click on the Google search button  
ele1.Click();  
Thread.Sleep(3000);  
//close the browser  
driver.Close();  
Console.Write("test case ended ");  
}  
}  
}  

令人惊叹的!谢谢你的快速回复!我试试看嘿!只是尝试了一下,这基本上就是我以前的Python项目所做的。。我可以在后台运行吗?@IMaestro是的,你可以。你可以在c#Dot.Net中使用很多解决方案,例如windows应用程序中的后台工作程序、线程,甚至你可以在Web应用程序中使用windows Service应用程序或HangFire软件包。我们这里有很多东西:)