背景:之前由于自己有编写CefSharp.WinForms 窗体版以及 接口化 WCF+CefSharp.WinForms的网站版本,但是由于某些原因,延伸出Selenium学习与研究

总结:selenium特点是在做自动化测试,如果公司需要自动化测试是个不错的选择,开发语言包含很多。你完全可以使用自己熟悉的语言进行开发,请查看 https://docs.seleniumhq.org/docs/ 通过几天的摸索,个人比较还是建议大家最后部署在windows平台,linux平台由于缺少可视化,在调试的时候会有很多坑。

1.C#调用selenium

   请参照 http://www.mamicode.com/info-detail-2746933.html

  1、我们新建一个C#控制台程序

  2、使用Nuget搜索以下依赖库

  需要引用的核心库是Selenium.RC,Selenium.Support,Selenium.WebDriver

     MvcWeb版也可以运行,挂在IIS可以很好运行

 

using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;




namespace Maxiot.ResourceServer.Controllers
{
    public class TestController : Controller
    {
        //
        // GET: /Test/

        public ActionResult Index()
        {
            return View();
        }



        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="accesstoken"></param>
        /// <param name="value">非空参数必须传入数据</param>
        /// <returns></returns>
        public JsonResult GetData()
        {
            try
            {
                using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver())
                {
                    driver.Navigate().GoToUrl("www.baidu.com");
                    var timeouts = driver.Manage().Timeouts();
                    Thread.Sleep(3000);
                    var source = "aaa" + driver.PageSource;
                    return Json(source, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {

                return Json(ex.Message, JsonRequestBehavior.AllowGet);
            }
        }
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2021-12-06
  • 2022-02-18
  • 2021-12-01
  • 2021-05-05
猜你喜欢
  • 2021-06-02
  • 2021-09-13
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
  • 2021-04-01
  • 2022-12-23
相关资源
相似解决方案