2017-02-22 60 views
1

我是新来的量角器。无法在控制台日志中打印定位器(webelement)

我声明了一个元素作为变量,如:

txtSearch : element(by.xpath('//input[@type="search"]')), 

在某些时候,我想记录的定位:

var clickOn = function(webElement) 
{ 
    webElement.click(); 
    console.log("Successfully clicked on the " + webElement); 
}; 

我打电话从规格此功能类似的文件 - clickOn (txtSearch)

Console.log我越来越喜欢 - Successfully clicked on the [object Object]

请在下面找到所需的详细信息:

节点版本:7.5.0

量角器版本:5.1.1

器浏览器:Chrome的

量角器配置文件:

exports.config = { 
     capabilities: { 
      browserName: 'chrome', 
      }, 
    onPrepare: function(){ 
     jasmine.getEnv().addReporter(reporter); 

     global.isAngularSite = function(flag) { 
      browser.ignoreSynchronization = !flag; 
     }; 
     browser.manage().timeouts().setScriptTimeout(60000); 
     browser.driver.manage().window().maximize(); 
    }, 


    seleniumServerJar: '../../protractor/selenium/selenium-server-standalone-2.52.0.jar', 
    chromeDriver: '../../protractor/selenium/chromedriver_2.27.exe', 
    directConnect: true, 
    framework: 'jasmine2', 
    seleniumAddress: 'http://localhost:4444/wd/hub', 
    specs: ['../PoC_Protractor/spec.js'], 

    jasmineNodeOpts: { 
     showColors: true, 
     defaultTimeoutInterval: 600000, 
     isVerbose: true 
    } 

我试着用webElement.locator().toString()但throwing-

失败:webElement.locator不是一个函数

+0

请您检查我的答案在.. toString()应该工作..你可以更新与你在那个前面尝试的问题 – AdityaReddy

+0

[量角器控制台日志]的可能重复(http://stackoverflow.com/questions/19941739/protractor-console-log) – Xotabu4

+0

[如何在量角器中打印webelement?]的可能的副本(http://stackoverflow.com/questions/42267387/how-to-print-the-webelement-in-massractor) –

回答

0

您可以随时输出定位器用于在使用webElement.locator().toString()。检查下面的代码片断的输出。

量角器规格:

describe('Locator testing by model', function(){ 
    it('automate user register form', function(){ 
     browser.get('http://www.way2automation.com/angularjs-protractor/registeration/#/login'); 
     var search = element(by.model('Auth.user.name')) 
     console.log(search.locator()) 
     console.log("Successfully clicked on the " + search.locator().toString()); 
     console.log(search.locator().toString()) 
    }); 
}); 

输出:

[14:01:48] I/local - Starting selenium standalone server... 
[14:01:48] I/launcher - Running 1 instances of WebDriver 
[14:01:49] I/local - Selenium standalone server started at http://10.96.61.119:56341/wd/hub 
Started 
{ findElementsOverride: [Function], toString: [Function] } 
Successfully clicked on the by.model("Auth.user.name") 
by.model("Auth.user.name") 
. 


1 spec, 0 failures 
Finished in 0.942 seconds 

[14:01:53] I/local - Shutting down selenium standalone server. 
[14:01:53] I/launcher - 0 instance(s) of WebDriver still running 
[14:01:53] I/launcher - internet explorer #01 passed 
+0

对不起。我仍然收到错误。这里下面是我的代码 var type = function(webElement,data)webElement.clear(); console.log(“Data”+ data +“已成功输入”); ()=> {“webElement.locator()。toString()”上的成功输入数据“+ data +”); –

0

嘿,好像你可能不会解决正确的方式承诺,请尝试使用 -

webElement.click().then(function(element){ 
     console.log(""Successfully clicked on the " + element); 
}; 
相关问题