FontWeight cannot be obtained in IE7

10 posts, 1 answers
  1. kovyar
    kovyar avatar
    42 posts
    Member since:
    Jul 2010

    Posted 09 Sep 2010 Link to this post

    Hi all,

    in our tests we must sometimes check if some text is bold.
    For this purpose we use code like following:

    Settings mySettings = new Settings(BrowserType.InternetExplorer, @"c:\log\");
    mySettings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
     
    Manager myManager = new Manager(mySettings);
    myManager.Start();
    myManager.LaunchNewBrowser();
    myManager.ActiveBrowser.NavigateTo("http://vkontakte.ru/login.php");
     
    //That's the "Login" button.
    Element link;
    link = myManager.ActiveBrowser.Find.ByXPath("//td/*/*/*/*/a[1]");
    HtmlControl lnk = new HtmlControl(link);
     
    String weight = lnk.GetComputedStyleValue("fontWeight");
    String style = lnk.GetComputedStyleValue("fontStyle");
    String size = lnk.GetComputedStyleValue("fontSize");
     
     
    Console.WriteLine(myManager.ActiveBrowser.BrowserType);
    Console.WriteLine("Size: {0}", size);
    Console.WriteLine("Weight: {0}", weight);
    Console.WriteLine("Style: {0}", style);
    myManager.Dispose();

    Well, in Firefox everything looks fine and the output is like that:
    FireFox
    Size: 11px
    Weight: 400
    Style: normal

    But in IE the output looks a bit strange:
    InternetExplorer
    Size: 11px
    Weight:
    Style: normal

    So, we can get all the information about the font but its weight.
    What is even better, that:
    1) our tests MUST work in IE7
    2) checking font-weight is a must-have point in lots of tests.

    Thus we need any way to check whether the text is bold or not.

    Looking forward for any useful ideas.

    Thanks,
    Yaroslav


  2. Nikolai
    Admin
    Nikolai avatar
    84 posts
    Member since:
    Sep 2012

    Posted 09 Sep 2010 Link to this post

    Hi kovyar,

    You can obtain the value directly from the Styles collection like this:

    var fontWeightValue = lnk.Styles["FONT-WEIGHT"];

    Hope this helps.

    Kind regards,
    Nikolai
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

  3. kovyar
    kovyar avatar
    42 posts
    Member since:
    Jul 2010

    Posted 09 Sep 2010 Link to this post

    Hello, Nikolay

    After execution fontWeightValue is null, so that is not a solution. 

    All the best,
    Yaroslav

  4. Nikolai
    Admin
    Nikolai avatar
    84 posts
    Member since:
    Sep 2012

    Posted 09 Sep 2010 Link to this post

    Hi kovyar,

    I inspected the page from you test. It seems there is not font-weight under IE 7 or 8. (see attachment)
    We working with the values from the browser's DOM. If there is no value we cannot show it.

    Best wishes,
    Nikolai
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

  5. kovyar
    kovyar avatar
    42 posts
    Member since:
    Jul 2010

    Posted 09 Sep 2010 Link to this post

    Hi Nikolay

    the example I provided was no good because 400 is the default value for font-weight.
    The other link on the page (XPATH:  //div/div/div/div/div/a[1]) is bold and is a better example.
    Please see the attachment.

    Best regards,
    Yaroslav

  6. Answer
    Nikolai
    Admin
    Nikolai avatar
    84 posts
    Member since:
    Sep 2012

    Posted 09 Sep 2010 Link to this post

    Hello kovyar,

    Yes I see the problem. Can you please try this:

    var fontWeight = lnk.CallMethod<string>("currentStyle.getAttribute('fontweight')");

    This is a direct request to the DOM so it should work.

    Kind regards,
    Nikolai
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

  7. kovyar
    kovyar avatar
    42 posts
    Member since:
    Jul 2010

    Posted 09 Sep 2010 Link to this post

    Thanks, Nikolai, this code works pretty fine in IE7 and gives me the value I need, so our tests will work. :)

    BTW, this piece of code fails in FF with the following exception: 

    ExecuteCommand failed!
    InError set by the client. Client Error:
    mozCommandProcessor: TypeError: document.getElementsByTagName("a")[6].currentStyle is undefined
    BrowserCommand (Type:'Action',Info:'NotSet',Action:'InvokeJsFunction',Target:'ElementId (tagName: '',occurrenceIndex: '-1')',Data:'document.getElementsByTagName('a')[6].currentStyle.getAttribute('fontweight')',ClientId:'Client_68e819bf-14e1-42ac-a431-6b27fdfae366',HasFrames:'False',FramesInfo:'',TargetFrameIndex:'-1',InError:'True',Response:'mozCommandProcessor: TypeError: document.getElementsByTagName("a")[6].currentStyle is undefined')
    InnerException: none.

    This doesn't make any problems to us right now, but this might be a bug, so I've decided to inform you just in case.

    Thanks a lot,
    Yaroslav

  8. Nikolai
    Admin
    Nikolai avatar
    84 posts
    Member since:
    Sep 2012

    Posted 10 Sep 2010 Link to this post

    Hello kovyar,

    This is expected. FF and IE javascript engines are different and so they have some difference in their DOM element objects' functions.  In FF the JS way to get the computated style is to obtained it from the document view like this:

    var fontWeigth =          document.defaultView.getComputedStyle(anchor,null).getPropertyValue('font-Weight');

    so you cannot use direct call to the object like the one in my previous post.

    Sincerely yours,
    Nikolai
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

  9. kovyar
    kovyar avatar
    42 posts
    Member since:
    Jul 2010

    Posted 10 Sep 2010 Link to this post

    Hi, Nikolay,

    and thanks for clarification. BTW, are you going to fix this in WebAii 2.0? (And when, if )
    We'd like to reuse our code written under WebAii 1.1 without rewriting it much.

    All the best, 
    Yaroslav

  10. Nikolai
    Admin
    Nikolai avatar
    84 posts
    Member since:
    Sep 2012

    Posted 10 Sep 2010 Link to this post

    Hello kovyar,

    We will try to fix it but unfortunately I cannot give you a time frame in which this will be done.

    Sincerely yours,
    Nikolai
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Back to Top