Selenium webdriver 启用";保存日志“;在chrome中使用chromedriver编程

Selenium webdriver 启用";保存日志“;在chrome中使用chromedriver编程,selenium-webdriver,google-chrome-devtools,selenium-chromedriver,Selenium Webdriver,Google Chrome Devtools,Selenium Chromedriver,如何为chrome开发者设置->首选项->导航时保留日志启用保留日志选项,使用chromeoptions.add_参数或通过将pref添加到DesiredCapabilities或以编程方式的任何其他方式。您可以从性能日志获得重定向。根据,下面是我在C#中所做的工作,应该可以在Python中进行移植: var options = new ChromeOptions(); var cap = DesiredCapabilities.Chrome(); var perfLogPrefs = new

如何为chrome开发者设置->首选项->导航时保留日志启用保留日志选项,使用chromeoptions.add_参数或通过将pref添加到DesiredCapabilities或以编程方式的任何其他方式。

您可以从
性能
日志获得重定向。根据,下面是我在C#中所做的工作,应该可以在Python中进行移植:

var options = new ChromeOptions();
var cap = DesiredCapabilities.Chrome();
var perfLogPrefs = new ChromePerformanceLoggingPreferences();
perfLogPrefs.AddTracingCategories(new string[] { "devtools.network" });
options.PerformanceLoggingPreferences = perfLogPrefs;
options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
ptions.SetLoggingPreference("performance", LogLevel.All);
var driver = new ChromeDriver(options);
var url = "https://some-website-that-will-redirect.com/";
driver.Navigate().GoToUrl(url);
var logs = driver.Manage().Logs.GetLog("performance"); //all your logs with redirects will be here
日志中循环,如果
message.params.redirectResponse.url
等于原始url,则
message.params.request.url
将包含重定向url

Node.JS使用webdriverio

var options = {
    desiredCapabilities: {
        browserName: 'chrome',
        loggingPrefs: {
            'browser': 'ALL',
            'driver': 'ALL',
            'performance': 'ALL'
        },
        chromeOptions: {
            perfLoggingPrefs: {
                traceCategories: 'performance'
            },
        }
    }
var client = webdriverio.remote(options);
await client.url(url);
var logs = await client.log('performance');
var navigations = parseLogs(logs, url);

function parseLogs(logs, url) {
    var redirectList = [];
    while (true) {
        var targetLog = (logs.value.find(l => {
            if (l.message.indexOf(url) == -1)
                return false;
            var rootMessage = JSON.parse(l.message);
            if (((((rootMessage || {}).message || {}).params || {}).redirectResponse || {}).url == url)
                return true;
            return false;
        }) || {}).message;
        if (!targetLog)
            break;
        if (redirectList.indexOf(url) != -1)
            break;
        redirectList.push(url);
        var targetLogObj = JSON.parse(targetLog);
        var nextUrl = ((((targetLogObj || {}).message || {}).params || {}).request || {}).url;

        if (nextUrl) {
            url = nextUrl;
            continue;
        }
        break;
    }
    return redirectList;
}

非常感谢。本主题的所有示例都涉及Java,ChromePerformanceLoggingPreferences似乎是特定于.Net的。我也在使用
WebDrivero
,所需功能:{browserName:'chrome',loggingPrefs:{'browser':'all',driver':'all',performance':'all',chromeOptions:{perfLoggingPrefs:{traceCategories:'performance'}}},然后var logs=await client.log('performance');这段代码似乎不再工作了
未知错误:无法解析功能:goog:chromeOptions from unknown错误:无法解析perflogingprefs from unknown错误:无法识别的性能日志选项:enabletime
有趣的是,它正在抱怨enabletime,它在all@Jan我已经切换到Node.js和只有当您need@Toolkit,你是否在VS中编写了节点应用程序?我当然想看看。