0

I try to get automatic click on a button on a page on my website I have try multiple things and i can not get out of this exception This is My code Well wen i press the button1 its come an error I describe below code

Public Class Form5
    Dim CheckButton, skip_ad_button As HtmlElement
    Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        WebBrowser1.ObjectForScripting = True
        WebBrowser1.ScriptErrorsSuppressed = True
    End Sub
    Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub



    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        skip_ad_button = WebBrowser1.Document.GetElementById("skip_ad_button")
        CheckButton = WebBrowser1.Document.GetElementById("skip_ad_button")

        If Not skip_ad_button Is Nothing Then
            skip_ad_button.InnerText = "skip_ad_button" 'Replace testID by the ID you want
        End If

        If Not CheckButton Is Nothing Then
            'some code here
        End If
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        WebBrowser1.Navigate("http:\\mediaads.eu/proxy")

    End Sub
End Class

This is the error

System.NotSupportedException was unhandled by user code HResult=-2146233067 Message=Property is not supported on this type of HtmlElement. Source=System.Windows.Forms StackTrace: at System.Windows.Forms.HtmlElement.set_InnerText(String value) at WindowsApplication1.Form5.WebBrowser1_DocumentCompleted(Object sender,

WebBrowserDocumentCompletedEventArgs e) in \Documents\Visual Studio 2012\Projects\WindowsApplication1\WindowsApplication1\Form5.vb:line 23

Steve
  • 213,761
  • 22
  • 232
  • 286
  • 1
    What is the HTML type of the element `skip_ad_button`? Is it an `input`, a `button`, or something else? Regardless of the answer, it is clear that you cannot set the `InnerText` property of that element - perhaps you need to set an attribute in order to accomplish whatever it is you are trying to accomplish... – RB. Jun 13 '17 at 12:32
  • [Turn `option strict` to ON](https://stackoverflow.com/a/29985039/5897829) – Martin Verjans Jun 13 '17 at 12:43
  • Yes its a button id element and i want to automatic press this button – Andreia Gosalves Jun 13 '17 at 12:50
  • I have try to set option strict to on but it continue to give me the same error how can i solve it – Andreia Gosalves Jun 13 '17 at 13:01
  • 1
    See @RB comment. what if you try `skip_ad_button.setAttribute("value", "skip_ad_button")` versus `skip_ad_button.InnerText = ...` – Jimmy Smith Jun 13 '17 at 13:32
  • 1
    Tank you @JimmySmith Now I Have No More Errors but wen the page is load and my website its come the button its the but there is no automatic click at all – Andreia Gosalves Jun 13 '17 at 13:47
  • Glad! When you say no automatic click, you cannot click the button now or it won't programmatically click it for you? – Jimmy Smith Jun 13 '17 at 17:16
  • Sorry what i mean its it should catch the attribute but nothing happen – Andreia Gosalves Jun 14 '17 at 13:05

0 Answers0