zoukankan      html  css  js  c++  java
  • C# Selenium操作指南,关闭黑色CMD窗口/禁用图片/隐藏浏览器等

    引用部分:
    1.


    2.


     
    配置部分:

    ChromeDriverService driverService = ChromeDriverService.CreateDefaultService();
    driverService.HideCommandPromptWindow = true;//关闭黑色cmd窗口
    
    ChromeOptions options = new ChromeOptions();
    // 不显示浏览器
    //options.AddArgument("--headless");
    // GPU加速可能会导致Chrome出现黑屏及CPU占用率过高,所以禁用
    options.AddArgument("--disable-gpu");
    // 伪装user-agent
    options.AddArgument("user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1");
    // 设置chrome启动时size大小
    options.AddArgument("--window-size=414,736");
    // 禁用图片
    options.AddUserProfilePreference("profile.default_content_setting_values.images", 2);
    
    IWebDriver webDriver = new ChromeDriver(driverService,options);
    //如果查找元素在5S内还没有找到
    webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); 
    string url = "https://www.baidu.com";
    webDriver.Navigate().GoToUrl(url);
     执行JS(将滚动条拉到底部):
    ((IJavaScriptExecutor)webDriver).ExecuteScript("window.scrollTo(0, document.body.scrollHeight)");
     获取标签(以多Class为例):
    ReadOnlyCollection<IWebElement> elements = webDriver.FindElements(By.CssSelector("[class='item goWork']"));
    --------------------- 

    https://www.cnblogs.com/NorthAlan/p/5156259.html  不错


    原文:https://blog.csdn.net/PLA12147111/article/details/92000480

  • 相关阅读:
    bzoj4554: [Tjoi2016&Heoi2016]游戏
    bzoj3166: [Heoi2013]Alo
    luogu3398 仓鼠找sugar
    bzoj3261: 最大异或和
    bzoj3446: [Usaco2014 Feb]Cow Decathlon
    BZOJ1742[Usaco2005 nov]Grazing on the Run 边跑边吃草
    bzoj2750: [HAOI2012]Road
    bzoj4448: [Scoi2015]情报传递
    bzoj2809: [Apio2012]dispatching
    bzoj 1452
  • 原文地址:https://www.cnblogs.com/wangchuang/p/11120497.html
Copyright © 2011-2022 走看看