简体   繁体   中英

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.

First of all, why not simply navigate to the value of the link? ie 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM