IsActiveElement not working properly

9 posts, 1 answers
  1. Wit
    Wit avatar
    24 posts
    Member since:
    Jul 2010

    Posted 26 Aug 2010 Link to this post

    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?
  2. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 30 Aug 2010 Link to this post

    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
  3. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 31 Aug 2010 Link to this post

    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
  4. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 10 Sep 2010 Link to this post

    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
  5. Wit
    Wit avatar
    24 posts
    Member since:
    Jul 2010

    Posted 10 Sep 2010 Link to this post

    Thank you.

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

  6. Answer
    Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 10 Sep 2010 Link to this post

    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
  7. Wit
    Wit avatar
    24 posts
    Member since:
    Jul 2010

    Posted 10 Sep 2010 Link to this post

    Just found this:
    ActiveBrowser.ContentWindow.SetFocus();

    It's usefull to make sure focus is on the document.
    I hope it works across all browsers.
  8. Kashyap
    Kashyap avatar
    6 posts
    Member since:
    Oct 2008

    Posted 24 Feb 2011 Link to this post

    Thanks wit,

    It help me fix my issue too. 
  9. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 24 Feb 2011 Link to this post

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