【问题标题】:How can i get network and endpoint info in firefox with selenium java?如何使用 selenium java 在 Firefox 中获取网络和端点信息?
【发布时间】:2021-08-13 21:56:07
【问题描述】:

我想用 selenium 从 Firefox 获取网络信息。我是用chrome驱动做的,像这样

logPrefs.enable( LogType.PERFORMANCE, Level.ALL );
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setCapability("goog:loggingPrefs", logPrefs);
chromeOptions.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

#and it is log code,

LogEntries logs = driver.manage().logs().get("performance");

我可以使用此代码获取网络日志和端点。我怎样才能从 Firefox 获得它?当我尝试它时,它给它一个错误。

Caused by: org.openqa.selenium.json.JsonException: Unable to determine type from: H. Last 1 characters read: H

谢谢

【问题讨论】:

    标签: java selenium firefox geckodriver


    【解决方案1】:

    使用 Java,这是一种获取网络请求的方法。输出可能更友好,但信息就在那里。

    public class CaptureNetworkTraffic {
    
    public static WebDriver driver;
    public static String driverPath = \
    
    @SuppressWarnings("deprecation")
    public static void main(String[] args) {
    
    System.setProperty("webdriver.chrome.driver", pathToDriver);
    
    DesiredCapabilities caps = DesiredCapabilities.chrome();
    
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.PERFORMANCE, Level.INFO);
    
    caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    
    driver= new ChromeDriver(caps);
    driver.get("https://www.edureka.co/");
    
    List<LogEntry> entries = driver.manage().logs().get(LogType.PERFORMANCE).getAll();
    
    System.out.println(entries.size() + " " + LogType.PERFORMANCE + " log entries found");
    
    for (LogEntry entry : entries) {
        System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
    
    }
    
    driver.close();
    driver.quit();
    
    }
    }
    

    【讨论】:

    • 嗨@C。 Peck,谢谢你的帮助,它是 chrome 的,我怎么能用 firefox 做同样的事情,当我尝试时它给出一个错误Caused by: org.openqa.selenium.json.JsonException: Unable to determine type from: H. Last 1 characters read: H
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    相关资源
    最近更新 更多