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

Cannot find HTMLAnchor by ID

5 Answers 119 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ronan
Top achievements
Rank 1
Ronan asked on 03 Sep 2015, 11:15 AM

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



​ 

 

5 Answers, 1 is accepted

Sort by
0
Pravallika
Top achievements
Rank 1
answered on 03 Sep 2015, 11:23 AM

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.

0
Ronan
Top achievements
Rank 1
answered on 03 Sep 2015, 11:23 AM

[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)​

0
Pravallika
Top achievements
Rank 1
answered on 03 Sep 2015, 11:37 AM

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.

0
Ronan
Top achievements
Rank 1
answered on 03 Sep 2015, 11:53 AM

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

0
Ronan
Top achievements
Rank 1
answered on 03 Sep 2015, 11:55 AM
Oops, Look like there is no functionality to edit my own post. Sorry for the wrong formatted snippet code :(
Tags
General Discussions
Asked by
Ronan
Top achievements
Rank 1
Answers by
Pravallika
Top achievements
Rank 1
Ronan
Top achievements
Rank 1
Share this question
or