• selenium获取浏览器控制台日志


    	public void logsTest(){
    		
    		WebDriver driver = null;
    		try {
    			System.setProperty("webdriver.chrome.driver", "resources/chromedriver.exe");
    			DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    			capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));
    			ChromeOptions options = new ChromeOptions();
    			options.addArguments("--test-type");
    			options.addArguments("start-maximized");
    			options.addArguments("chrome.switches", "--disable-extensions");
    			capabilities.setCapability("chrome.binary", "resources/chromedriver.exe");
    			capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    			driver = new ChromeDriver(capabilities);
    			driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
    			driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
    		} catch (Exception se) {
    			Log.logInfo(se.getMessage());
    		}	
    		
    		driver.get("http://rosewholesale.com.trunk.s1.egomsl.com/index.html");
    		LogEntries logEntries =driver.manage().logs().get(LogType.BROWSER);
    	    for(LogEntry entry : logEntries) {
    	        System.out.println("chrome.console===="+" "+entry.getLevel() +" "+ entry.getMessage());
    	    }
    	}
    

    运行结果:

    Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 6093
    Only local connections are allowed.
    五月 21, 2018 2:24:17 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
    信息: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
    log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
    五月 21, 2018 2:24:20 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
    信息: Detected dialect: OSS
    chrome.console==== SEVERE http://rosewholesale.com.trunk.s1.egomsl.com/index.html - Failed to load resource: the server responded with a status of 404 (Not Found)
    chrome.console==== SEVERE http://gloimg.rowcdn.com/ROSE/pdm-product-pic/Electronic/2016/05/23/goods-img/1463976912184411330.jpg - Failed to load resource: the server responded with a status of 403 (Forbidden)
    chrome.console==== SEVERE http://gloimg.rowcdn.com/ROSE/pdm-product-pic/Electronic/2016/04/26/goods-img/1461695301583672699.jpg - Failed to load resource: the server responded with a status of 403 (Forbidden)
    chrome.console==== SEVERE http://gloimg.rowcdn.com/ROSE/pdm-product-pic/Clothing/2016/04/05/goods-img/1475200054575036741.jpg - Failed to load resource: the server responded with a status of 403 (Forbidden)
    chrome.console==== SEVERE http://gloimg.rowcdn.com/ROSE/pdm-product-pic/Electronic/2016/08/18/goods-img/1471476045701329163.jpg - Failed to load resource: the server responded with a status of 403 (Forbidden)
    chrome.console==== SEVERE http://gloimg.rowcdn.com/ROSE/pdm-product-pic/Electronic/2016/09/02/goods-img/1472858627506353802.jpg - Failed to load resource: the server responded with a status of 403 (Forbidden)
    chrome.console==== SEVERE http://gloimg.rowcdn.com/ROSE/pdm-product-pic/Clothing/2016/06/11/goods-img/1465750515681302230.jpg - Failed to load resource: the server responded with a status of 403 (Forbidden)
    chrome.console==== SEVERE http://gloimg.rowcdn.com/ROSE/pdm-product-pic/Electronic/2016/09/03/goods-img/1472858347691220531.jpg - Failed to load resource: the server responded with a status of 403 (Forbidden)
    chrome.console==== SEVERE http://gloimg.rowcdn.com/ROSE/pdm-product-pic/Electronic/2016/04/26/goods-img/1461634414942098965.jpg - Failed to load resource: the server responded with a status of 403 (Forbidden)

  • 相关阅读:
    浅析软件开发项目的前期沟通工作
    .net core 和 WPF 开发升讯威在线客服系统:实现对 IE8 的完全完美支持 【干货】
    产品的定价策略(一):想通过产品挣钱,首先你产品的目标客户得不差钱
    .net core 和 WPF 开发升讯威在线客服系统:使用线程安全的 BlockingCollection 实现高性能的数据处理
    .net core 和 WPF 开发升讯威在线客服系统:使用 TCP协议 实现稳定的客服端
    .net core 和 WPF 开发升讯威在线客服系统:使用 WebSocket 实现访客端通信
    Centos上配置两层nginx转发,把请求转发到外网
    真实字节二面:什么是伪共享?
    关于MVCC,我之前写错了,这次我改好了!
    从家庭主妇到格力老总,董明珠的大女主逆袭之路
  • 原文地址:https://www.cnblogs.com/lincj/p/9067362.html
Copyright © 2020-2023  润新知