• 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)

  • 相关阅读:
    Java基础知识【上】(转载)
    Windows下Python中pip安装Pillow报错总结(转载)
    CentOS7下安装Python的pip
    CentOS7安装NodeJS6.9
    PostGIS(解压版)安装
    CentOS7中安装Python3.5
    CentOS7安装docker
    Centos7更改默认启动模式(转载)
    CentOS7 查看IP、Gateway、DNS、Hostname
    CentOS7系统安装及初始化
  • 原文地址:https://www.cnblogs.com/lincj/p/9067362.html
Copyright © 2020-2023  润新知