HtmlControl.Click() clicking wrong control

4 posts, 0 answers
  1. Dave Hanna
    Dave Hanna avatar
    3 posts
    Member since:
    Sep 2009

    Posted 01 Jul 2010 Link to this post

    First of all, is the free edition of WebAii acquired form ArtOfTest before the acquisition still supported?  I downloaded it about a year ago because it was free, and now I can't find any reference to it on the site, and the ArtOfTest.com site is basically defunct.

    I've used that edition of the WebAii framework quite a bit, so I know it basically works.  So the problem I'm having now is completely baffling to me.

    I'm trying to test navigation in an existing site, and going through a sequence of pages.  I get to a page that has (among other things) two buttons.  One is a "back" button that is an input element of type button with an onclick handler that calls a javascript function that just calls history.back().  The other is a submit button.

    WebAii has no problem finding the submit button.  But when I tell it to click it, it is, to all appearances, clicking the back button.

    Here's the relevant HTML from the site:

    <div align="right"
        <table border="0" width="200" cellpadding="8" style="border-collapse: collapse" bordercolor="#E0DFE3"
            <tr> 
                <td> 
                    <input type="button" value="<- Back" name="B2" onclick="cancelChange()" > 
                </td> 
                <td> 
                    <input type="submit" value="Maint Details ->" name="lnkSubmit"
                </td> 
            </tr> 
        </table> 
    </div> 
     

    And here's the test code:
                HtmlInputSubmit maintDetailsButton = Find.ByAttributes<HtmlInputSubmit>("value=Maint Details ->"); 
                maintDetailsButton.Click(); 
     
                Assert.IsTrue(ActiveBrowser.Url.Contains(expectedPage), "URL {0} does not contain expected page {1}", ActiveBrowser.Url, expectedPage); 
     

    The sequence of operations is working just fine when I click it manually, so I can see no evidence that it's the site's problem.  I've seen abundant evidence that it is, in fact, clicking the "Back" button and not the "Maint Details" button. (Fiddler shows no request issued when the click request is sent - consistent with executing history.back(), since the browser simply redisplays from it's cache.  When I click, it does, in fact, go to the previous page.  And finally, if I remove the "onclick" attribute from the back button, so that clicking on the button does nothing, then when execute the test code, the site does nothing - simply stays on the current page.)

    I am completely baffled.  Can anyone give me a hint? 
  2. Dave Hanna
    Dave Hanna avatar
    3 posts
    Member since:
    Sep 2009

    Posted 01 Jul 2010 Link to this post

    Well, it's taken me a week of beating my head against the wall, but I did figure this out.

    First, I discovered something. From what I've been able to deduce, when you do a Find.<something>, WebAii keeps track of that element as an index into a list of all the elements of that type in the document.  Then, whenever you access a found element, WebAii will generate a JavaScript function of the form "document.GetElementsByTag('<tagtype>')[<indexNumber>].<whatever method>"  I discovered this accidentally when I trying to find a way to identify the element that WebAii had found, and inadvertently generated a javascript error which displayed the function it was trying to execute in the exception.
    So, then I reasoned that if it's accessing the element by index, and somehow or another its index is off, then it would make sense that it was clicking the input element before the one I wanted it to.
    So I did a Find.AllByTagName("input"), and looked through the resulting ReadOnlyCollection in the VS debugger, and started matching the input elements that it found with what I could identify looking at a View Source of the page.  I discovered that I was finding one that WebAii wasn't listing, way up near the top of the page, and, on closer examination discovered that the input element that was missing was missing it's closing angle bracket.
    So, apparently WebAii did not find that as an input element, but javascript did.  So when my test said "maintDetails.Click()", that was being converted into something like "document.GetElementsByTag('input')[20].click()", when, because of the missing element, it should have been "document.GetElementsByTag('input')[21].click()".

    I fixed up the missing closing angle bracket in the site source code, and the test ran.
  3. Missing user
    Missing user avatar

    Posted 02 Jul 2010 Link to this post

    Hello Dave,

    We are still supporting the framework and you can check out the latest on it here.

    I'm glad you got this working, it seems thought that tracking down a missing bracket would still be problematic even with support here.

    You can try using Find Expressions to include more find information for the button like name, type, etc to try to get a specific handle on that button

    But please feel free to post any further WebAii questions or issues in the ticket system.

    Kind regards,
    Nelson Sin
    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. Dave Hanna
    Dave Hanna avatar
    3 posts
    Member since:
    Sep 2009

    Posted 02 Jul 2010 Link to this post

    Thanks for the reply, Nelson.

    It's good to know it's still supported, and even a new update.

    I agree, that one was hard to find, and would have been even with support.  The actual problem was so far removed from the symptom, until you figure out what's going on under the covers.


Back to Top