3

I am trying to click the button highlighted in picture below. The code is from a web page:

enter image description here

I'm not to sure, but I believe the button is within an iFrame.

I have tried:

Dim wrapClick As HtmlElement = Contact.WebBrowser1.Document.GetElementById("Btn_WrapUp")
wrapClick.InvokeMember("Click")

And:

Dim elPoint As New Point(704, 340)
Dim wrapClick As HtmlElement = Contact.WebBrowser1.Document.GetElementFromPoint(elPoint)
wrapClick.InvokeMember("onClick")

And:

Contact.WebBrowser1.Document.GetElementById("Btn_WrapUp").InvokeMember("Click")

In all of the above, I have tried 'onClick' and 'Click'.

WebBrowser1 is on a different form.

Thanks!

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
Jack
  • 45
  • 1
  • 5
  • 1
    Hmm I try this with some html in iframe... I see empty iframe (where is html?) and error "Object reference not set to an instance of an object". Without iframe, InvokeMember works with no errors. – c4pricorn Nov 04 '15 at 18:57
  • 1
    Ok, I see html in iframe, but have no access to elements. _"Access to frames is complicated by the fact that the managed HTML DOM implements a security measure known as cross-frame scripting security."_ And InvokeMember on element in iframe returns "access denied". See https://msdn.microsoft.com/en-us/library/ms171715.aspx – c4pricorn Nov 04 '15 at 19:35
  • Thank you for your reply. So, does this mean it is not possible to click this button pragmatically? Is the any other methods other than InvokeMember I can try? @capricorn – Jack Nov 04 '15 at 21:35
  • Please bare in mind I am at a beginner level with vb.net and below that in HTML – Jack Nov 04 '15 at 21:36
  • 1
    It seems that it is not possible to click a button on a html placed in an iframe. For security reasons. Am afraid that there is no other method. In html without iframe, click works. – c4pricorn Nov 04 '15 at 22:26
  • Could I not even execute the 'onClick' command: "activityHelperObj.WrapUp(); return false;" or the jQuery using code? Without having to actually click the button. @capricorn – Jack Nov 05 '15 at 08:32

1 Answers1

1

Click button in WebBrowser control - working example:

Main file with frame - x.html:

<html>
<body>
<iframe width="400" height="300" src="y.html" id="frame1"> </iframe>
</body>
</html>

File placed in frame - y.html - with submit button:

<html>
<body>
<form action="...some_action...">
<input type="submit" id="btn"> Submit!
</form>
</body>
</html>

Button on VB form with OnClick event:

Dim Frame1 As HtmlWindow = WebBrowser1.Document.Window.Frames("frame1")
Frame1.Document.GetElementById("btn").InvokeMember("click")

VB2010Ex & .NET Framework 4 Client Profile. I have tried code with action that load other site. Site was loaded in iframe. Finally success :-)

c4pricorn
  • 3,471
  • 1
  • 11
  • 12