3 Replies - 929 Views - Last Post: 03 July 2013 - 07:43 AM Rate Topic: -----

#1 aristide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-December 11

[SIMPLE] Webbrowser click on Link (Dynamic)

Posted 02 July 2013 - 12:14 PM

Hello there. I have a very simple question. I have to click a link in my webbrowser, but the poblem is that the link isn't constant, and a part of it always changes. What remains the same is the word "logout". I have this code, but it doesn't work.

For Each link As HtmlElement In WebBrowser1.document.Links
            If link.InnerText.Contains = "logout" Then
                WebBrowser1.Navigate(link.GetAttribute("href"))
                Exit For
            End If
        Next

What do i have to do? The link looks like this:

./ucp.php?mode=logout&battlegate_prod_sid=605bbad188f836f4c8b0a7959145074e


Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: [SIMPLE] Webbrowser click on Link (Dynamic)

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,473
  • Joined: 12-June 08

Re: [SIMPLE] Webbrowser click on Link (Dynamic)

Posted 02 July 2013 - 12:29 PM

So whatcha trying to automate with Battledawn?
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4313
  • View blog
  • Posts: 12,090
  • Joined: 18-April 07

Re: [SIMPLE] Webbrowser click on Link (Dynamic)

Posted 02 July 2013 - 12:39 PM

Well InnerText is going to give you the text of the link. That is the text between the <a></a> tags. So if the link text is called "logout" then you should be using...

If link.InnerText = "logout" then
    ' Do navigation
End if



Now you can't put something like this in the document completed event or else the browser will immediately start navigating. So what you will need to do is trap the link using an event. The following site can show you how to do that. Trap the link and in the LinkClicked event handler, that page sets up, you would check the InnerText and then if it equals the logout you can use the link.GetAttribute("href") to get access to the link href and put it into the navigation request.

http://www.codeproje...r-Link-Trapping

It really doesn't matter what the href value actually is. Even if it changes getting the href attribute should give you the correct value.
Was This Post Helpful? 0
  • +
  • -

#4 aristide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-December 11

Re: [SIMPLE] Webbrowser click on Link (Dynamic)

Posted 03 July 2013 - 07:43 AM

View PostMartyr2, on 02 July 2013 - 12:39 PM, said:

Well InnerText is going to give you the text of the link. That is the text between the <a></a> tags. So if the link text is called "logout" then you should be using...

If link.InnerText = "logout" then
    ' Do navigation
End if



Now you can't put something like this in the document completed event or else the browser will immediately start navigating. So what you will need to do is trap the link using an event. The following site can show you how to do that. Trap the link and in the LinkClicked event handler, that page sets up, you would check the InnerText and then if it equals the logout you can use the link.GetAttribute("href") to get access to the link href and put it into the navigation request.

http://www.codeproje...r-Link-Trapping

It really doesn't matter what the href value actually is. Even if it changes getting the href attribute should give you the correct value.
Thanks. I read the article, I have to admit I didn't understand all of it, but the majority, and I don't think that's what is needed.

I know how it is when noobs asks questions, that you can never understand what they are asking.

Basically i need to be sure that the browser clicks on a link, which part of it contains "logout"

Maybe that's what you where trying to explain, but it didn't work our for me.

EDIT: Oh and if it helps i want to put it in a button, not document completed

This post has been edited by aristide: 03 July 2013 - 07:45 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1