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

IsActiveElement not working properly

8 Answers 80 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Wit
Top achievements
Rank 1
Wit asked on 26 Aug 2010, 10:26 AM
I tried using HTMLInputText.IsActiveElement but it doesn't seem to work properly.
When running my test:
[Test]
public void GoogleTest()
{
    Manager.LaunchNewBrowser();
    ActiveBrowser.NavigateTo("http://www.google.com");
 
     
    HtmlInputText queryBox = Find.ByName<HtmlInputText>("q");
    Log.WriteLine(queryBox.IsActiveElement.ToString());
    Desktop.Mouse.Click(MouseClickType.LeftClick, queryBox.GetRectangle());
    Desktop.KeyBoard.TypeText("sample", 1000);
     
    Actions.Click(Find.ById("btnG"));
}

I can see that focus is in the url address box and not the search input box. queryBox.IsActiveElement is true so it's incorrect.
I also noticed that ActiveBrowser.NavigateTo works differently than launching the page manually.
In the first case focus is in the url address box in the latter its in search box.

1. Why IsActiveElement wrong?
2. Why NavigatTo works differently than manually?

8 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 30 Aug 2010, 08:24 AM
Hi Wit,

Thank you for posting about these issues.

It seems in IE ownerDocument.activeElement returns wrong value. Although this looks like a browser issue we will need to investigate it to find if a work-around is possible so I've logged a bug. I've also logged a bug about the NavigateTo behavior while running the test.

Thank you for the feedback!

Sincerely yours,
Konstantin Petkov
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
Konstantin Petkov
Telerik team
answered on 31 Aug 2010, 04:42 PM
Hi Wit,

Just a follow up. It seems the NavigateTo behavior comes from IE and we have no control over that. You can check it by running "internet explorer" in windows Start/Run menu.

We will investigate the active element issue.

Regards,
Konstantin Petkov
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
Konstantin Petkov
Telerik team
answered on 10 Sep 2010, 12:31 PM
Hello Wit,

Just noticed the IsActiveElement issue is resolved as designed in our database as well. This behavior is expected since the URL Box is not part of the HTML Document and is part of IE's chrome instead. IsActiveElement is scoped to the document which in this case is correct since the cursor is in the box.

I hope this info helps!

Greetings,
Konstantin Petkov
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
Wit
Top achievements
Rank 1
answered on 10 Sep 2010, 02:07 PM
Thank you.

Is there any way to find out that document has focus and not the browser elements?

0
Accepted
Konstantin Petkov
Telerik team
answered on 10 Sep 2010, 02:15 PM
Hi Wit,

Just got this and this from a quick search. There are probably more useful resources available on the matter.

Greetings,
Konstantin Petkov
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
Wit
Top achievements
Rank 1
answered on 10 Sep 2010, 03:02 PM
Just found this:
ActiveBrowser.ContentWindow.SetFocus();

It's usefull to make sure focus is on the document.
I hope it works across all browsers.
0
Kashyap
Top achievements
Rank 1
answered on 24 Feb 2011, 07:20 PM
Thanks wit,

It help me fix my issue too. 
0
Cody
Telerik team
answered on 24 Feb 2011, 08:55 PM
Hello Kashyap,

I am glad Wit's answer helped you out. That is the correct way to force the browser window to get focus. 

Wit,

That call should work for all browsers. Please let us know if you have any problems with this.

You originally asked how to detect if the browser window/document currently has focus. Konstantin did give some useful links on how to do this. Were these helpful or did you actually just want to force the focus on the browser, per the code sample you already posted?

Kind regards,
Cody
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
General Discussions
Asked by
Wit
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
Wit
Top achievements
Rank 1
Kashyap
Top achievements
Rank 1
Cody
Telerik team
Share this question
or