none
Interact in C # with a web page RRS feed

  • Question

  • Hello, I created a launcher to download a game. This button on "Download" is available on the HTML page integrated into CEFSHARP (web browser with chrome engine). It starts the download from the launcher.

    Here is the code I use to download a file

     WebClient client = new WebClient();
                    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                    client.DownloadFileCompleted += Client_DownloadFileCompleted;
                    client.DownloadFileAsync(new Uri("fileURL"), System.IO.Path.Combine(fbd2.SelectedPath, "test.7z"));

    But instead of pressing a button, I want to press a button on a website.


    sorry for my English





    Sunday, April 7, 2019 10:31 PM

All replies

  • Hi Dropper7894,

    Thank you for posting here.

    >>But instead of pressing a button, I want to press a button on a website.

    For your question, it seems like you use a buttin on website. ASP.NET is a good choice. You could create a website and when you press the button on the website, the file downloaded.

    If you need further help of ASP.NET, you could get help from ASP.NET forum.

    https://forums.asp.net/

    BestRegards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 8, 2019 5:43 AM
    Moderator
  • If you are trying to automate the pressing of a button on a web page then you aren't going to be able to do that directly. You have limited options.

    1) Use the WebBrowser control and see if you can click the button from that (never tried it).

    2) Download the HTML using WebClient, find the button in the HTML using HtmlAgilityPack or similar, grab the href it is going to and then sending that (probably POST) request via WebClient to trigger the button action. However this would rely on the site not having any client-side code to execute.

    This is really completely and utterly dependent upon the site you're trying to work with.


    Michael Taylor http://www.michaeltaylorp3.net

    Monday, April 8, 2019 2:04 PM
    Moderator
  • You will need to read the CeFSharp documentation.  You can pass a C# object into the Javascript on your web page, so the Javascript "click" handler for your button calls a C# method.  I think that's what you are asking for.

    It might be easier to do it all from Javascript.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, April 8, 2019 7:00 PM
  • You need to use Selenium.  C# supports Selenium with Edge, Chrome and Firefox.  Starting with Windows 10 1809 the Selenium Edge Driver is built into OS.


    Here is an example:

    using System;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Edge;
    
    namespace Selenium2
    {
        class Program
        {
            static void Main(string[] args)
            {
                IWebElement ele;
                IWebDriver drv = new EdgeDriver();
                drv.Url = "http://nm.sirsi.net/uhtbin/cgisirsi/RbT1VTQSO7/CEN/41670105/60/1182/X";
                ele = drv.FindElement(By.XPath("//a[contains(text(),'Advanced Search')]"));
                ele.Click();
                drv.Close();
                Environment.Exit(0);
            }
        }
    }

    • Edited by mogulman52 Monday, April 8, 2019 11:29 PM
    Monday, April 8, 2019 11:14 PM