Jasmine 无法在控制台日志中打印定位器(webelement)

Jasmine 无法在控制台日志中打印定位器(webelement),jasmine,protractor,Jasmine,Protractor,我不熟悉量角器 我将元素声明为变量,如下所示: txtSearch : element(by.xpath('//input[@type="search"]')), 在某些情况下,我希望将定位器记录为: var clickOn = function(webElement) { webElement.click(); console.log("Successfully clicked on the " + webElement); }; 我从Spe

我不熟悉量角器

我将元素声明为变量,如下所示:

txtSearch : element(by.xpath('//input[@type="search"]')),
在某些情况下,我希望将定位器记录为:

var clickOn = function(webElement)
{
  webElement.click();
  console.log("Successfully clicked on the " + webElement);
};
我从Spec文件调用这个函数,比如-
clickOn(txtSearch)

Console.log
中,我成功地点击了[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()
,但它正在抛出-

失败:webElement.locator不是函数


您始终可以使用
webElement.locator().toString()
输出使用的定位器。检查以下代码snipper的输出

量角器规格:

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

您始终可以使用
webElement.locator().toString()
输出使用的定位器。检查以下代码snipper的输出

量角器规格:

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

嘿,看起来您可能没有以正确的方式解决承诺,请尝试使用-

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

嘿,看起来您可能没有以正确的方式解决承诺,请尝试使用-

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

请在下面核对我的答案。。toString()应该可以工作。。你能用你在这方面的尝试来更新这个问题吗?可能的重复请检查我下面的答案。。toString()应该可以工作。。你能用你在这方面的尝试来更新这个问题吗?也可能是抱歉的重复。。!!我仍然得到错误。下面是我的代码
var type=function(webElement,data){webElement.clear();console.log(“数据”+data+”在上输入成功”);return webElement.sendKeys(data)。然后(()=>{console.log(“在”+webElement.locator().toString()上成功输入数据”+data+)
对不起,yaar..!!我仍然收到错误。下面是我的代码
var type=function(webElement,data){webElement.clear();console.log(“data”+data+“在上输入成功”);返回webElement.sendKeys(data)。然后(()=>{console.log(“在”+webElement.locator()上成功输入数据”+data+).toString());