GetStyle() throws exception (c#)

4 posts, 0 answers
  1. tsjax
    tsjax avatar
    8 posts
    Member since:
    Sep 2016

    Posted 15 Dec 2016 Link to this post

    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

  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1072 posts

    Posted 20 Dec 2016 Link to this post

    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
     
  3. tsjax
    tsjax avatar
    8 posts
    Member since:
    Sep 2016

    Posted 20 Dec 2016 in reply to Boyan Boev Link to this post

    This seems to make all the difference.

    Thanks a lot for your help.

    Regards

  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1072 posts

    Posted 21 Dec 2016 Link to this post

    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
     
Back to Top