3 Replies - 914 Views - Last Post: 09 October 2012 - 01:57 AM Rate Topic: -----

#1 aff219@gmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-October 12

How to use a list to navigate webbrowser1?

Posted 09 October 2012 - 12:23 AM

Disclaimer: I'm a noob to programming, just got a load of freetime (became self employeed woo!) and decided to learn something I've always wanted to learn. Therefore, I need gentle yet thorough guidance please.

I decided to join a browser based game (name will be left out in all this) and use it as a learning block for this.

I've accomplished quite a lot in my program, but I'm stuck between a rock and a hard place now.

2 big issues I'm having:

Issue 1 - Locating target values and navigating to their assigned URL.

Relevent HTML Code:
<map name="ValueMap">
     <area alt="USE B 11" href="region.php?reg=2">
     <area alt="open" href="region.php?reg=3">
     <area alt="open" href="region.php?reg=4">
     <area alt="USE C 324" href="region.php?reg=5">
     <area alt="open" href="region.php?reg=6">
     <area alt="USE D 32" href="region.php?reg=7">
     <area alt="open" href="region.php?reg=8">
     <area alt="open" href="region.php?reg=9">
     <area alt="open" href="region.php?reg=10">
     <area alt="open" href="region.php?reg=11">
     <area alt="open" href="region.php?reg=12">
</map>


Notes:
the Alt value is able to contain similar and exact terms as each other. For instance, 2 may be "open", some might be "use b 11", some might be "use b 12" etc


What I want:
1.navigate webbrowser1 to the url contained in the first area tag that has an alt with my searched value.

So if I want to find "D", the program will grab
<area alt="USE D 32" href="region.php?reg=7">
and use its url to navigate in the web browser.

I've had partial success with this with 3 different methods, but all lead to an issue i cant get around so I'm willing to start fresh. The best way ive had yet was with this code:

        Dim Items = _
        ( _
        From T In Form2.WebBrowser1.document.GetElementsByTagName("alt").Cast(Of HtmlElement)() _
        Where T.GetAttribute("href").ToString.Contains("region.php?reg=") _
        Select Link = T.GetAttribute("href"), Text = T.InnerText _
        ).ToList
        ListBox1.Items.AddRange(Items.ToArray)



But frankly I couldn't figure out how to use that information to navigate to URL (It also seemed to pull more than purely the url, instead of JUST the url it would display "url = ********* Text=" and i couldnt figure out how to fix that, nor could I figure out how to use it to navigate the webbrowser to the page it obtained, then while trying for a few hours I somehow managed to break it <.<

2. click a button on the page it navigates to from goal 1 if 2 variables are true
variable 1: if ____ is located in the HTML code
variable 2: if it states "USE 2" & >= predefined number

seems easy enough right? theres tons of guides on the net for this sort of thing, but for lord only knows why, I can't make it work for this site. I can with others, not this one.

relevant HTML (The form/html code for the button):
	<form method="post" action="region.php">
    <td align="center"><br><br>
	<input type="hidden" name="regionId" value="2">
	<input type="hidden" name="transId" value="7457995">
		<input type="hidden" name="ownerName" value="USE D">
	<input type="submit" value="gain!" name="submit4221" style="color: #FF0000; font-family: Verdana; font-size: 10pt; font-weight: bold; background-color: #FFFFFF">
	<input type="hidden" name="action" value="gain">
	</td>
	</form>



the value="USE D" is a variable that will change but i dont htink it matters
name="submit4221" is a partial variable, the digits at the end can change per page load (wont always)

i've tried about 3 different things, all i can say is submitting a click doesnt seem to accomplish diddly.


Can anyone here give me any tips? I've been at this for over a week and I can't seem to find anything to get me over these hurdles, lots and lots of googling and a forum or two have helped me get this far, but i never seem to get these questions answered

*** actually therse one more noobie question i have, what is the best way to tell your program to wait for webpage1 to finish loading before continuing, WITHOUT coding things directly into the webpage (i don't intend to have it in use and dont want to code directly to it, eventually i want to remove it completely once i get this beta version finished)

I've read a few ways but none seem to be perfect answers

Is This A Good Question/Topic? 0
  • +

Replies To: How to use a list to navigate webbrowser1?

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: How to use a list to navigate webbrowser1?

Posted 09 October 2012 - 01:20 AM

Quote

*** actually therse one more noobie question i have, what is the best way to tell your program to wait for webpage1 to finish loading before continuing, WITHOUT coding things directly into the webpage (i don't intend to have it in use and dont want to code directly to it, eventually i want to remove it completely once i get this beta version finished)

Are you aware of the WebBrowser.DocumentCompleted event? I'd use that to set a Boolean value to true and then a certain code will be able to run, or just call the code from within the event.
Was This Post Helpful? 0
  • +
  • -

#3 aff219@gmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-October 12

Re: How to use a list to navigate webbrowser1?

Posted 09 October 2012 - 01:45 AM

View PostDimitriV, on 09 October 2012 - 01:20 AM, said:

Quote

*** actually therse one more noobie question i have, what is the best way to tell your program to wait for webpage1 to finish loading before continuing, WITHOUT coding things directly into the webpage (i don't intend to have it in use and dont want to code directly to it, eventually i want to remove it completely once i get this beta version finished)

Are you aware of the WebBrowser.DocumentCompleted event? I'd use that to set a Boolean value to true and then a certain code will be able to run, or just call the code from within the event.


i tried if webbrowser.documentcompleted = true then type things, none of them seemed to be very effective, ill read up on what boolean value is (i've used it a couple times now but unsure of what its actually doing) and give it a shot, thanks for the help on that part
Was This Post Helpful? 0
  • +
  • -

#4 aff219@gmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 08-October 12

Re: How to use a list to navigate webbrowser1?

Posted 09 October 2012 - 01:57 AM

View Postaff219@gmail.com, on 09 October 2012 - 01:45 AM, said:

View PostDimitriV, on 09 October 2012 - 01:20 AM, said:

Quote

*** actually therse one more noobie question i have, what is the best way to tell your program to wait for webpage1 to finish loading before continuing, WITHOUT coding things directly into the webpage (i don't intend to have it in use and dont want to code directly to it, eventually i want to remove it completely once i get this beta version finished)

Are you aware of the WebBrowser.DocumentCompleted event? I'd use that to set a Boolean value to true and then a certain code will be able to run, or just call the code from within the event.


i tried if webbrowser.documentcompleted = true then type things, none of them seemed to be very effective, ill read up on what boolean value is (i've used it a couple times now but unsure of what its actually doing) and give it a shot, thanks for the help on that part



actually, little update here...

the current method im using actually works with boolean (i admit, i stole this bit of code from another forum question somewhere) is as follows:

#Region "Call - WaitForPageLoad() - waits for browser to finish loading"
    Private Property pageready As Boolean = False
    Private Sub WaitForPageLoad()
        AddHandler Form2.WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
        While Not pageready
            Application.DoEvents()
        End While
        pageready = False
    End Sub

    Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
        If Form2.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
            pageready = True
            RemoveHandler Form2.WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
        End If
    End Sub
#End Region



it works without error, but it appears that sometimes bits of code get past it i guess is the best way to say it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1