This is a migrated thread and some comments may be shown as answers.

GetStyle() throws exception (c#)

3 Answers 30 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
tsjax
Top achievements
Rank 1
tsjax asked on 15 Dec 2016, 08:44 PM

Hello,

I am trying to do something seemingly simple and that is to get the background color of a particular element in order to validate whether or not it is correct based on the business rules. The element in questions follows this configuration:

<input id="someID" class="there is some information here" tabindex="-32767" title="title" style="background-color: rgb(255, 50, 50); border-width: 2px; border-style: inset; border-image: none;" type="text">

 

I am not having any trouble accessing the element and its various attributes. However, regarding the style 'background-color', I get into trouble:

HtmlInputText el = <the element referenced above>;
var bgColor = el.GetStyle("background-color");    //  <---- Throws an exception (Invalid Operation Exception).

The problem is the style, "background-color" very clearly exists as you can see in bold above. However, I cannot figure out a reliable and elegant way to pull it out and get its value. Perhaps my approach to this problem is going down the wrong track?

Thanks for your help,

tsjax

3 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 20 Dec 2016, 09:04 AM
Hello Travis,

Since this is a computed style please change the code to:

HtmlStyle backGroundCollor = el.GetComputedStyle("background-color");

Let me know if that helps.

Regards,
Boyan Boev
Telerik by Progress
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
tsjax
Top achievements
Rank 1
answered on 20 Dec 2016, 02:33 PM

This seems to make all the difference.

Thanks a lot for your help.

Regards

0
Boyan Boev
Telerik team
answered on 21 Dec 2016, 08:43 AM
Hi Travis,

You are most welcome.

If you need further assistance please let us know.

Regards,
Boyan Boev
Telerik by Progress
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
tsjax
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
tsjax
Top achievements
Rank 1
Share this question
or