Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.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 getTitle()在Selenium Webdriver上给出奇怪的结果_Javascript_Node.js_Selenium_Selenium Webdriver_Phantomjs - Fatal编程技术网

Javascript getTitle()在Selenium Webdriver上给出奇怪的结果

Javascript getTitle()在Selenium Webdriver上给出奇怪的结果,javascript,node.js,selenium,selenium-webdriver,phantomjs,Javascript,Node.js,Selenium,Selenium Webdriver,Phantomjs,我正在SeleniumWebDriver中结合Phantomjs环境运行一个自动测试脚本 我正在尝试通过node.js运行脚本(不使用Python或C#) 以下是我如何设置环境的步骤: 安装selenium Web驱动程序: C:\xampp\htdocs\testPhantomJS\>npm安装selenium webdriver 安装phantomJS 将phantomjs脚本放在以下位置: C:\xampp\htdocs\testPhantomJS\node\u modules\selen

我正在SeleniumWebDriver中结合Phantomjs环境运行一个自动测试脚本

我正在尝试通过node.js运行脚本(不使用Python或C#)

以下是我如何设置环境的步骤:

  • 安装selenium Web驱动程序:
    C:\xampp\htdocs\testPhantomJS\>npm安装selenium webdriver

  • 安装phantomJS 将phantomjs脚本放在以下位置:
    C:\xampp\htdocs\testPhantomJS\node\u modules\selenium webdriver

  • 运行独立的selenium服务器:

  • 下面是我正在运行的测试脚本[login as administrator.js]:

    var webdriver = require('selenium-webdriver');
    var By = require('selenium-webdriver').By;
    var until = require('selenium-webdriver').until;
    var equals = require('selenium-webdriver').equals;
    var driver = new webdriver.Builder()
        .withCapabilities(webdriver.Capabilities.phantomjs())
        .build();
    var baseUrl = 'http://saswatr3.ouh.co/login';
    var expectedTitle = " Track Revenue ";
    
    driver.get(baseUrl);
    var actualTitle = driver.getTitle();
    console.log(actualTitle);
    if(expectedTitle === actualTitle)
    {
        console.log("Verification Successful - The correct title is displayed on the web page.");
    }
    else
    {
        console.log("Verification Failed - An incorrect title is displayed on the web page.");
    }
    driver.manage().window().maximize();
    driver.findElement(By.id('username')).sendKeys('saswat@matrixnmedia.com');
    driver.findElement(By.id('password')).sendKeys('DarkPrince2012');
    driver.findElement(By.id('_submit')).click();
    driver.wait(until.titleIs('Track Revenue'), 1000);
    driver.quit();
    
    我通过node.js运行上述脚本

    C:\xampp\htdocs\testPhantomJS\node\u modules\selenium webdriver>node以管理员身份登录。js

    当我运行此脚本时,我得到如下报告:

    正如您所看到的,当将
    actualTitle
    放到日志中时,我得到了一个奇怪的结果


    我不明白为什么会有这么奇怪的报道。是否有我遗漏的内容?

    getTitle
    计划一个命令,该命令将在稍后由WebDriverJS框架执行(在您的情况下,在加载页面时)。它返回一个承诺,而不是标题

    试试这个:

    driver.getTitle().then(function(title) {
    
        if(expectedTitle === title){
            console.log("Verification Successful - The correct title is displayed on the web page.");
        }
        else{
            console.log("Verification Failed - An incorrect title is displayed on the web page.");
        }
    });
    
    而不是:

    var actualTitle = driver.getTitle();
    console.log(actualTitle);
    if(expectedTitle === actualTitle)
    {
        console.log("Verification Successful - The correct title is displayed on the web page.");
    }
    else
    {
        console.log("Verification Failed - An incorrect title is displayed on the web page.");
    }
    
    另外,删除预期标题的额外空格,如:

    var expectedTitle = "Track Revenue";
    

    getTitle
    计划WebDriverJS框架稍后(在您的情况下,当加载页面时)执行的命令。它返回一个承诺,而不是标题

    试试这个:

    driver.getTitle().then(function(title) {
    
        if(expectedTitle === title){
            console.log("Verification Successful - The correct title is displayed on the web page.");
        }
        else{
            console.log("Verification Failed - An incorrect title is displayed on the web page.");
        }
    });
    
    而不是:

    var actualTitle = driver.getTitle();
    console.log(actualTitle);
    if(expectedTitle === actualTitle)
    {
        console.log("Verification Successful - The correct title is displayed on the web page.");
    }
    else
    {
        console.log("Verification Failed - An incorrect title is displayed on the web page.");
    }
    
    另外,删除预期标题的额外空格,如:

    var expectedTitle = "Track Revenue";
    

    getTitle
    计划WebDriverJS框架稍后(在您的情况下,当加载页面时)执行的命令。它返回一个承诺,而不是标题

    试试这个:

    driver.getTitle().then(function(title) {
    
        if(expectedTitle === title){
            console.log("Verification Successful - The correct title is displayed on the web page.");
        }
        else{
            console.log("Verification Failed - An incorrect title is displayed on the web page.");
        }
    });
    
    而不是:

    var actualTitle = driver.getTitle();
    console.log(actualTitle);
    if(expectedTitle === actualTitle)
    {
        console.log("Verification Successful - The correct title is displayed on the web page.");
    }
    else
    {
        console.log("Verification Failed - An incorrect title is displayed on the web page.");
    }
    
    另外,删除预期标题的额外空格,如:

    var expectedTitle = "Track Revenue";
    

    getTitle
    计划WebDriverJS框架稍后(在您的情况下,当加载页面时)执行的命令。它返回一个承诺,而不是标题

    试试这个:

    driver.getTitle().then(function(title) {
    
        if(expectedTitle === title){
            console.log("Verification Successful - The correct title is displayed on the web page.");
        }
        else{
            console.log("Verification Failed - An incorrect title is displayed on the web page.");
        }
    });
    
    而不是:

    var actualTitle = driver.getTitle();
    console.log(actualTitle);
    if(expectedTitle === actualTitle)
    {
        console.log("Verification Successful - The correct title is displayed on the web page.");
    }
    else
    {
        console.log("Verification Failed - An incorrect title is displayed on the web page.");
    }
    
    另外,删除预期标题的额外空格,如:

    var expectedTitle = "Track Revenue";
    

    天哪!你是天才。谢谢兄弟@CViejo。。我也会有一些问题,但这个我会接受的。你能帮我解决其他问题吗?天哪!你是天才。谢谢兄弟@CViejo。。我也会有一些问题,但这个我会接受的。你能帮我解决其他问题吗?天哪!你是天才。谢谢兄弟@CViejo。。我也会有一些问题,但这个我会接受的。你能帮我解决其他问题吗?天哪!你是天才。谢谢兄弟@CViejo。。我也会有一些问题,但这个我会接受的。你能帮我解决其他问题吗?