Unable to print the locator (webelement) in Console Log
Team,
I am declaring an element as a variable like txtSearch : element(by.xpath('//input[@type="search"]')), in some point I want to log the locator as var clickOn = function(webElement){ webElement.click(); console.log("Successfully clicked on the " + webElement); };
I am calling this function from Spec file like clickOn (txtSearch)
In Console.log I am getting like Successfully clicked on the [object Object]. Also, this console.log is logging the console before the statement gets executed i.e. first all the console.log statement is executing first even before URL has launched.
Please find the required details below:
- Node Version:
3.10.3 - Protractor Version:
4.0.3 - Angular Version: ``
- Browser(s):
Chrome - Operating System and Version ``
- Your protractor configuration file
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.21.exe',
directConnect: true,
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['../PoC_Protractor/spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 600000,
isVerbose: true
}_
Thanks in advance.
console.log will print types of objects if you connect them with text. There are two options. Either use console.log(webElement); and print your text in a different console.log or use second parameter to specify objects, so: console.log('your text %s', webElement); .Take a look here for more information.
Also this isn't the right place to ask questions about issues that aren't related to the framework. I would suggest asking on StackOverflow. There are number of questions that might help you in the future.
Hi @fcin,
Thanks for your input. But I am not getting the expected after trying above methods. Let me start a new thread in StackOverflow,
Thanks again.
webElement.locator().toString() - This help in printing the locator.
If you are using console.log(), you have to do this:
className.attributeName.then(function(someText) {
console.log('The text found in this element is: ' + someText);
});
Because console.log() is handled first, so you have to make it a promise.