Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取控制台日志错误代码selenium js_Javascript_Selenium_Selenium Webdriver_Monitoring_Synthetic - Fatal编程技术网

Javascript 获取控制台日志错误代码selenium js

Javascript 获取控制台日志错误代码selenium js,javascript,selenium,selenium-webdriver,monitoring,synthetic,Javascript,Selenium,Selenium Webdriver,Monitoring,Synthetic,下面是我在selenium JS中的代码,在最后一步,我想从浏览器控制台获取错误代码,我需要检查,当前页面的浏览器控制台中不应该有任何504错误代码 driver.get(M_URL) .then(() => { return driver.findElement(By.xpath('//input[@id="UserName"]')) .then(el => el.sendKeys(USERNAME));

下面是我在selenium JS中的代码,在最后一步,我想从浏览器控制台获取错误代码,我需要检查,当前页面的浏览器控制台中不应该有任何504错误代码

driver.get(M_URL)
    .then(() => {
        return driver.findElement(By.xpath('//input[@id="UserName"]'))
            .then(el => el.sendKeys(USERNAME));
    })
    .then(() => {
        return driver.findElement(By.xpath('//input[@id="Password"]'))
            .then(el => el.sendKeys(PASSWORD));
    })
    .then(() => {
        return driver.findElement(By.xpath('//button[text()="Login"]'))
            .then(el => el.click());
    })
    .then(() => {
    return driver.findElement(By.xpath('//h3[text()[contains(.,"Publisher")]]')).click()
        .then(() => log('Publisher page is rendered'));
    })
    .then(() => log('check 504 error code in browser console'));

提前谢谢

下面是你如何做到这一点的

require('chromedriver');

const path = require('path');
const wd = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

var builder = new wd.Builder();
var options = new chrome.Options();
var prefs = new wd.logging.Preferences();
var driver;

prefs.setLevel(wd.logging.Type.BROWSER, wd.logging.Level.ALL);
options.setLoggingPrefs(prefs);

driver = builder
    .forBrowser(wd.Browser.CHROME)
    .setChromeOptions(options)
    .build();

driver
    .get(`file://${path.resolve(__dirname, './page.html')}`)
    .then(() => driver.manage().logs().get(wd.logging.Type.BROWSER))
    .then((logs) => {
        console.log(logs);
    })
    .then(() => driver.quit());
更多信息