WebBrowser contains text

Posts 1–15 of 19 · Page 1 of 2
WebBrowser contains text
What am i doing wrong?

Code:
        If WebBrowser1.DocumentText.Contains("Please try this code instead") Then
            Label9.Text = ("Catpcha is wrong. Please try again!")
            Label9.ForeColor = Color.Red
        Else
        End If
This doesnt work. When i put this in the timer it will always put label9 as "Captcha is wrong...." How do i make it so that when the phrase "Please try this code instead" appears, it will make label9 write "catpcha wrong". Apparently i am doing something wrong...
Code seems fine to me, what is your browser pointing to so I can do some testing.
yahoo registration. so when i fill in wrong captcha the phrase "please try this code again" will show up and the label9 will turn "catpcha is wrong."
that still wont work thought.
cause that phrase will only appear if a wrong captcha is inputted.
please check on yahoo. fill in all info and put in wrong capthca. it will then say the phrase like wrong code or something. but the web address never changes.

so how can i detect this phrase?
oo i think i know the problem. when the timer starts it automatically searches for the phrase. but the phrase only shows up when a wrong captcha is inputted. how can i get this to work?
If webbrowser1.readystate = true then
yada yada
else
end if
Maybe something like this:

Code:
    if webbrowser1.readystate = complete..... then


  If WebBrowser1.DocumentText.Contains("Please try this code instead") Then
            Label9.Text = ("Catpcha is wrong. Please try again!")
            Label9.ForeColor = Color.Red
        Else
       Label9.Text = (You have entered the right Captcha. Good Job!")
            Label9.ForeColor = Color.green

        End If

else

msgbox("Please wait")
end if

And add it to a button(maybe Valid as name)
this is what i hve so far:
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
            If WebBrowser1.DocumentText.Contains("Please try this code instead") Then
                Label9.Text = ("Catpcha is wrong. Please try again!")
                Label9.ForeColor = Color.Red
            Else
                Label9.Text = ("You have entered the right Captcha. Good Job!")
                Label9.ForeColor = Color.Green
            End If
        Else
            MsgBox("Please wait")
        End If
    End Sub
End Class
but i still get the same error:
Code:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Windows.Forms.dll
for this line
Code:
 If WebBrowser1.DocumentText.Contains("Please try this code instead") Then
It still trys to find that phrase. but it only shows up if u input a wrong captcha after u press submit captcha.
it keeps searching for the line "Please try this code instead" even thought it is not there. how do i bypass this? code above...
Ok, I see.........

Your looking for something that isn't there

Use

Try
If WebBrowser1.DocumentText.Contains("Please try this code instead") Then
yadaYadaYada
Catch
DoEvents
Msgbox (Ex.message)
End Try

Use this and tell me what the error is .
(when it pops up)

After that, remove the msgbox (ex.message) and it should bypass the error

Note: Bad Programming concepts, but should work

ty it worked. u da best.
would that work for more than 1 error like:
Code:
    Try
            If WebBrowser1.DocumentText.Contains("Please try this code instead") Then
                TextBox1.Text = ("Catpcha is wrong. Please try again!")
            End If
            If WebBrowser1.DocumentText.Contains("This ID is not available") Then
                TextBox1.Text = ("Email ID taken.")
            End If
            If WebBrowser1.DocumentText.Contains("This postal code is not located in the country you selected") Then
                TextBox1.Text = ("Postal code not recognized.")
            End If
        Catch
        End Try
    End Sub
i tried it but it didnt work.
[FONT="Times New Roman"][COLOR="DarkOliveGreen"]No but you can do

Code:
 Try
            If WebBrowser1.DocumentText.Contains("Please try this code instead") Then
                TextBox1.Text = ("Catpcha is wrong. Please try again!")
            End If
       Catch
        End Try

Try 
            If WebBrowser1.DocumentText.Contains("This ID is not available") Then
                TextBox1.Text = ("Email ID taken.")
           Catch 
End try 

Try 
 End If
            If WebBrowser1.DocumentText.Contains("This postal code is not located in the country you selected") Then
                TextBox1.Text = ("Postal code not recognized.")
            End If
Catch 
End try
OR

Code:
Try
            
Yada Yada 
        Catch 

        Catch 
 Catch 

        Catch 
 Catch 

        Catch 
Finally
End try
Depending on if you are trying to catch multiple errors of one instance or vice versa
If for some reason you have issues using multiple try(s) then use DoEvents
yah i tried this.

Code:
 'Email ID
        Try
            If WebBrowser1.DocumentText.Contains("This ID is not available") Then
                TextBox1.Text = ("Email ID taken.")
            End If
        Catch
        End Try

        'Captcha
        Try
            If WebBrowser1.DocumentText.Contains("Please try this code instead") Then
                TextBox1.Text = ("Catpcha is wrong. Please try again!")
            End If
        Catch
        End Try

        'Postal Code
        Try
            If WebBrowser1.DocumentText.Contains("This postal code is not located in the country you selected") Then
                TextBox1.Text = ("Postal code not recognized.")
            End If
        Catch
        End Try
    End Sub
but it doesnt work.

it only works when i have one of the codes.
wat would if i want to place the errors individually.
so if wrong captcha. right to textbox.
if wrong postal code. right to textbox.
Posts 1–15 of 19 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us