Page 1 of 1

Find element and click on it

PostPosted: Mon Feb 24, 2020 5:30 am
by Uliani4
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.

Re: Find element and click on it

PostPosted: Fri Feb 28, 2020 8:42 am
by Uliani4
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,