Find element and click on it

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

Find element and click on it

Postby Uliani4 » Mon Feb 24, 2020 5:30 am

Hi guys.

I decided to refactor one of my projects using the CEF, I can’t do one thing, could you direct me on the right path.

This program is an automated bot (information collector). The site has many frames.

How it worked before changing the code with a standard Webbrowser.

Code: Select all
private void goHotel()
        {
            HtmlElementCollection frame_tag;

            frame_tag = webBrowserHunt.Document.GetElementsByTagName("iframe");

            foreach (HtmlElement he in frame_tag)
            {
                if (he.Name.Contains("header"))
                {
                    HtmlWindow doc              = he.Document.Window.Frames[he.Name];
                    HtmlElementCollection a_tag = doc.Document.GetElementsByTagName("a");

                    foreach (HtmlElement hEl in a_tag)
                    {
                        if (hEl.OuterHtml.Contains("Hotel"))
                        {
                            hEl.InvokeMember("click");
                            break;
                        }
                    }
                    break;
                }
            }
        }


The method found I need a frame, in this case (header)
Then in this frame I found the link I needed (element <a> of the "Hotel") and performed the click method.

Code: Select all
<a class="menutop" onclick="this.blur(); jumptopath('/main.pl?edit='); return false;" href="#">Hotel</a>


I can’t figure out how to use the CEF to find me this element and click on it.

Thank you very much in advance.
Uliani4
Newbie
 
Posts: 3
Joined: Mon Feb 24, 2020 5:05 am

Re: Find element and click on it

Postby Uliani4 » Fri Feb 28, 2020 8:42 am

Resolved

Code: Select all
var identifiers = webBrowserHunt.GetBrowser().GetFrameIdentifiers();

foreach (var i in identifiers)
{
    frame = webBrowserHunt.GetBrowser().GetFrame(i);

    if (frame.Name.Contains("header"))
    {
        frame_tag = webBrowserHunt.GetBrowser().GetFrame(frame.Name);
        break;
    }
}

frame_tag.EvaluateScriptAsync("jumptopath('/main.pl?edit=')");


Thanks,
Uliani4
Newbie
 
Posts: 3
Joined: Mon Feb 24, 2020 5:05 am


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 4 guests