cancel
Showing results for 
Search instead for 
Did you mean: 

[TechCorner Challenge #13] Get properties of a web page element

SOLVED
Highlighted
Community Manager

[TechCorner Challenge #13] Get properties of a web page element

Hi TestComplete Community,

 

A new TechCorner task today - we will be working with the DOM Document object.

By completing the tasks, you can practice your skills of working with TestComplete features and also get into the TechCorner Leaderboard!

 

Task: You will need to find the “Start a topic” button on this page and get the following info about it: color, font family, and font size and post the script and the log info below.

Difficulty:Star_Gold.pngStar_gray.pngStar_gray.png

 

The button you'll be interacting with:

2020-09-22_14-52-54.png

 

For this:

1. Get the element.

2. Obtain the element style as described in the documentation: Getting Computed Styles.

3. Log the values of the following style properties: backgroundColor, fontFamily, and fontSize.

 

Good luck!😊


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

Get properties of a web page element

Task: You will need to find the “Start a topic” button on this page and get the following info about it: color, font family, and font size and post the script and the log info below.

 

This is a solution created for [TechCorner Challenge #13]

//Solution in Javascript

function test2()
{
var url = "https://community.smartbear.com/t5/TestComplete-General-Discussions/TechCorner-Challenge-13-Get-prop...";

Browsers.Item(btChrome).Run(url);
var page = Sys.Browser().Page(url);
var element = page.FindChildByXPath("//*[@class='NewTopic-link']");
var style = page.contentDocument.defaultView.getComputedStyle(element, "");
Log.Message("The Properties of web page element are as follows")
Log.Message("Background Color : " + style.backgroundColor);
Log.Message("Font Family : " + style.fontFamily);
Log.Message("Font Size : " + style.fontSize);
}

View solution in original post

Tags (1)
4 REPLIES 4
Highlighted
Occasional Contributor

Get properties of a web page element

Task: You will need to find the “Start a topic” button on this page and get the following info about it: color, font family, and font size and post the script and the log info below.

 

This is a solution created for [TechCorner Challenge #13]

//Solution in Javascript

function test2()
{
var url = "https://community.smartbear.com/t5/TestComplete-General-Discussions/TechCorner-Challenge-13-Get-prop...";

Browsers.Item(btChrome).Run(url);
var page = Sys.Browser().Page(url);
var element = page.FindChildByXPath("//*[@class='NewTopic-link']");
var style = page.contentDocument.defaultView.getComputedStyle(element, "");
Log.Message("The Properties of web page element are as follows")
Log.Message("Background Color : " + style.backgroundColor);
Log.Message("Font Family : " + style.fontFamily);
Log.Message("Font Size : " + style.fontSize);
}

View solution in original post

Tags (1)
Highlighted
Community Manager

Re: [TechCorner Challenge #13] Get properties of a web page element

Great job @prekar ! Congrats on finishing one more task!

 

P.S. could you post the resulting log however?🙂 


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Occasional Contributor

Re: [TechCorner Challenge #13] Get properties of a web page element

Result Log

prekar_0-1600898610790.png

 

Highlighted
Community Manager

Re: [TechCorner Challenge #13] Get properties of a web page element

Thank you for posting this @prekar ! Great job there.


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors