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

FontWeight cannot be obtained in IE7

9 Answers 112 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kovyar
Top achievements
Rank 1
kovyar asked on 09 Sep 2010, 10:57 AM
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


9 Answers, 1 is accepted

Sort by
0
Nikolai
Telerik team
answered on 09 Sep 2010, 11:47 AM
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
0
kovyar
Top achievements
Rank 1
answered on 09 Sep 2010, 11:54 AM
Hello, Nikolay

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

All the best,
Yaroslav

0
Nikolai
Telerik team
answered on 09 Sep 2010, 12:26 PM
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
0
kovyar
Top achievements
Rank 1
answered on 09 Sep 2010, 12:40 PM
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
0
Accepted
Nikolai
Telerik team
answered on 09 Sep 2010, 01:58 PM
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
0
kovyar
Top achievements
Rank 1
answered on 09 Sep 2010, 02:37 PM
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

0
Nikolai
Telerik team
answered on 10 Sep 2010, 05:54 AM
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
0
kovyar
Top achievements
Rank 1
answered on 10 Sep 2010, 09:29 AM
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
0
Nikolai
Telerik team
answered on 10 Sep 2010, 09:35 AM
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
Tags
General Discussions
Asked by
kovyar
Top achievements
Rank 1
Answers by
Nikolai
Telerik team
kovyar
Top achievements
Rank 1
Share this question
or