【问题标题】:Unable to print the locator (webelement) in Console Log无法在控制台日志中打印定位器(webelement)
【发布时间】:2022-02-25 22:02:38
【问题描述】:

我是 Protractor 的新手。

我将一个元素声明为一个变量,例如:

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 我越来越喜欢 - 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(),但它正在抛出-

失败:webElement.locator 不是函数

【问题讨论】:

标签: jasmine protractor


【解决方案1】:

您始终可以使用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

【讨论】:

  • 对不起你..!!我仍然收到错误消息。下面是我的代码var type = function(webElement, data){ webElement.clear(); console.log("Data " + data +" entered successful on "); return webElement.sendKeys(data).then(()=> { console.log("Successfully entered the data " + data + " on the " + webElement.locator().toString());
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    • 2011-11-25
    • 2019-01-21
    • 2016-12-20
    • 2023-04-01
    • 1970-01-01
    相关资源
    最近更新 更多