CodyMan
CodyMan

Reputation: 153

how to click on anchor tag in c# using gecko browser engine

I'm trying to click on the link that contains the text "Next". I've tried this code in c# using gecko web browser engine:

Gecko.DOM.GeckoLinkElement next = new Gecko.DOM.GeckoLinkElement(geckoWebBrowser1.Document.GetElementsByClassName("single-prev-next")[0].LastChild.DomObject);

next.Click();

Here is the Html of the website :

<div class="single-prev-next" style="float:right">
<span class="picture-of">Photo 3 of 8 </span>
<div id="prevre">
</div>
<a href="http://website.com/to/150810/4/">Next</a>
</div>

That's not working at all.

Upvotes: 0

Views: 2612

Answers (1)

Bartosz
Bartosz

Reputation: 4766

First of all, why not simply navigate to the value of the link? i.e. browser.Navigate("http://website.com/to/150810/4/");

I don't think it will make any difference based on your page code sample and will be faster and easier.

If you need to click though... This is not the way to do it - you are not actualy creating a new Link element after all. Therefore, something along the lines

GeckoAnchorElement link =   (GeckoAnchorElement)browser.Document.GetElementsByClassName("single-prev-next")[0].LastChild;
link.Click();

Upvotes: 1

Related Questions