Cannot find HTMLAnchor by ID

6 posts, 0 answers
  1. Phuc
    Phuc avatar
    4 posts
    Member since:
    Jul 2015

    Posted 03 Sep 2015 Link to this post

    Hi guys, I dont quite understand the problem below.

    I has a hyperlink element in HTML like this (telerik calls HTMLAnchor).

    <a href="#" id="btnSubmit" >Submit</a>​

    Now, what I all need that I want to find the <a> element by using HTMLAnchor, then click on it.

    Here is my vb code in my Telerik script

    ~~~~~

    Dim btnSubmit As ArtOfTest.WebAii.Controls.HtmlControls.HtmlAnchor
    Dim alertDialog__1 As AlertDialog = AlertDialog.CreateAlertDialog(ActiveBrowser, DialogButton.OK)
    alertDialog__1.HandlerDelegate = New DialogHandlerDelegate(AddressOf MyCustomAlertHandler)
    Manager.DialogMonitor.AddDialog(alertDialog__1)

    ActiveBrowser.Window.SetFocus
    ActiveBrowser.RefreshDomTree
    btnSubmit=Manager.ActiveBrowser.Find.ById("btnSubmit")
    Assert.IsNotNull(btnSubmit,"Cannot find the Submit button")
    btnSubmit.Click 
    alertDialog__1.WaitUntilHandled(50000)​

     ~~~~~

    BUT, the problem is that btnSubmit is NULL. Look like it can not find the element

    Log file:

    Value of type 'ArtOfTest.WebAii.ObjectModel.Element' cannot be converted to 'ArtOfTest.WebAii.Controls.HtmlControls.HtmlAnchor'.

    Any suggestion for me, guys.

    Thanks



    ​ 

     

  2. Pravallika
    Pravallika avatar
    14 posts
    Member since:
    Dec 2014

    Posted 03 Sep 2015 in reply to Phuc Link to this post

    Hi,

    In your code, Dim btnSubmit As ArtOfTest.WebAii.Controls.HtmlControls.HtmlAnchor (You declared it as HtmlControl of type HtmlAnchor.

    Later, btnSubmit=Manager.ActiveBrowser.Find.ById("btnSubmit") (This expression returns an object of type 'Element')

    The variable is not able to cast from HtmlAnchor to Element, which is why the exception in log as u mentioned (Value of type 'ArtOfTest.WebAii.ObjectModel.Element' cannot be converted to 'ArtOfTest.WebAii.Controls.HtmlControls.HtmlAnchor'.)

    You may want to try adding the element to elements explorer and use it as :

    btnSubmit = Pages.PageName.Elementname;

    Please give it a try!

     

    Thanks,

    Pravallika.

  3. Phuc
    Phuc avatar
    4 posts
    Member since:
    Jul 2015

    Posted 03 Sep 2015 in reply to Phuc Link to this post

    [Updating infomation]

    I changed the line

    btnSubmit=Manager.ActiveBrowser.Find.ById("btnSubmit")​
    to 

    btnSubmit=Manager.ActiveBrowser.Find.ById(Of HtmlAnchor)("btnSubmit")

    and the error "cannot be converted" above is gone.
    but, I have another one

    ArtOfTest.Common.Exceptions.AssertException: Cannot find the Submit button - [Expected:Not Null],[Actual:Null]
       at ArtOfTest.Common.UnitTesting.Assert.IsNotNull(Object value, String message)​

  4. Pravallika
    Pravallika avatar
    14 posts
    Member since:
    Dec 2014

    Posted 03 Sep 2015 Link to this post

    Dim abc As HtmlAnchor = Pages.Google.AnchorElement

    Assert.IsNotNull(abc)

     

    This works for me. May be increase your wait time or RefreshDomTree() before this call.

  5. Phuc
    Phuc avatar
    4 posts
    Member since:
    Jul 2015

    Posted 03 Sep 2015 Link to this post

    Hi Pravallika,

    I have updated as your the first suggestion, and my new code as shown below

    Dim btnSubmit As ArtOfTest.WebAii.Controls.HtmlControls.HtmlSpan
    Dim alertDialog__1 As AlertDialog = AlertDialog.CreateAlertDialog(ActiveBrowser, DialogButton.OK)
    alertDialog__1.HandlerDelegate =
    New DialogHandlerDelegate(AddressOf MyCustomAlertHandler)<br>Manager.DialogMonitor.AddDialog(alertDialog__1)
    ActiveBrowser.Window.SetFocus
    ActiveBrowser.RefreshDomTree
    btnSubmit=Pages.userEditPage.SubmitSpan<br>Assert.IsNotNull(btnSubmit,
    "Cannot find the Submit button")
    btnSubmit.Click
    alertDialog__1.WaitUntilHandled(5000)
    And now I can detect the expected element and click on it successfully. :D

    OK, next problem is that, after clicking on Submit button, there is an alert popup of the browser, and Telerik cannot click on OK button to close the alert popup (OK button of the alert popup).

    I got the exception message like this

    Exception thrown executing coded step: '[HandleBrowserDialog] : Handle Browser Alert Dialog'.
    InnerException:
    ArtOfTest.WebAii.Exceptions.ExecuteCommandException: ExecuteCommand failed!
    BrowserCommand (Type:'Information',Info:'DocumentMarkup',Action:'NotSet',Target:'null',Data:'',ClientId:'4cc3ea42-ee11-42fc-954f-eef38f38616b',HasFrames:'False',FramesInfo:'',TargetFrameIndex:'-1',InError:'False',Response:'')
    InnerException: System.TimeoutException: Timed out waiting for command to be handled

  6. Phuc
    Phuc avatar
    4 posts
    Member since:
    Jul 2015

    Posted 03 Sep 2015 in reply to Phuc Link to this post

    Oops, Look like there is no functionality to edit my own post. Sorry for the wrong formatted snippet code :(
Back to Top