Check if a property exist for an object
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Check if a property exist for an object
Hello everyone,
I am looking for a way to find out in a script if an HTML object has a specific property.
Thanks
- Labels:
-
Script Tests
-
Web Testing
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you use the Object Spy tool, it will list all the exposed properties of the UI Object.
Or do you mean verifying a property, if so, see aqObject.CompareProperty Method
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@rraghvani wrote:If you use the Object Spy tool, it will list all the exposed properties of the UI Object.
Or do you mean verifying a property, if so, see aqObject.CompareProperty Method
Sorry, I have corrected my original post. I meant in a script, so via javascript code.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@rraghvani wrote:See aqObject.CheckProperty Method
Thanks but this method evaluate the Value of a Property of an Element and not if the Property exist for the Element
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hopefully, I understand what you mean now. Try this,
function CheckProperty()
{
const Name = {
Firstname: "SmartBear"
}
Log.Message(Name.Firstname);
Log.Message(Name.hasOwnProperty("Firstname")); // true
Log.Message(Name.hasOwnProperty("Surname")); // false
}
Use "hasOwnProperty()"
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
> if an HTML object has a specific property
I believe that you are looking for how to check if HTML object (actually - html markup for the given element) has not a specific property, but some specific attribute, aren't you?
In this case use the .hasProperty() html built-in method accessible from within TestComplete.
https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute
https://www.w3schools.com/jsref/met_element_hasattribute.asp
/Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use this method :
//javascript
var hasProperty = aqObject.IsSupported(obj, "property_name");
if "hasProperty" is true, then the property is available on your object and you can interact with. If false, then the property does not exist in your object.
