Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Elm couldn't find popup download button
#7
Hi dear Gintaras, 

The code (for Edge Browser) worked very well except for name syntax error occasionally.  The error code is like this 
Warning: Failed to download. IOException, The filename, directory name, or volume label syntax is incorrect.   at line 36.

Besides, Plese advise if there is anything improper in the code. Thank you very much! 

PS, Most of the code was learned from your examples in the forum, Most sincere thanks to you!  Heart

 I have made some donations to the site. lol
 
Code:
Copy      Help
// script "Notes-box.com3.cs"
///*/ role exeProgram; outputPath %folders.Workspace%\exe\Notes-box.com; /*/
using System.Net.Http;
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.MediaStop, pauseKey: KKey.MediaPlayPause);
//..
filesystem.createDirectory(folders.Desktop + @"notes-box");
var w = wnd.find(0, "*", "Chrome_WidgetWin_1");
var p = new ChromePage(w);

p.Open("https://notes-box.com/notes/classical-music/");
500.ms();
for (int i = 1; i < 85; i++) {
    dialog.show("downloading。。。", secondsTimeout: 2);
    p.Open($"https://notes-box.com/notes/classical-music/?PAGEN_1={i}");
    500.ms();
    foreach (var song in w.Elm["web:IMAGE", prop: "@loading=lazy"].FindAll().Select(o => o.Navigate("pa").Value).ToArray()) {
        p.Open(song);
        200.ms();
        var composer = w.Elm["web:LINK", prop: "@ru=Классческая", navig: "pr la"].Find(10).Name;
        var download = folders.Desktop + $@"notes-box\classical\{composer}\";
        pathname.correctName(download);
        //filesystem.delete(download);
        filesystem.createDirectory(download);
        var click = w.Elm["web:LINK", prop: "@ru=Классческая", navig: "ne6"].Find(3);
        click.Invoke();
        200.ms();
        var button = w.Elm["web:LINK", "DOWNLOAD FILE"].Wait(0);
        100.ms();
        button.SendKeys("Apps");
        var w2 = wnd.find(5, "", "Chrome_WidgetWin_?", "msedge.exe", contains: "Save link as");
        var save = w2.Elm["MENUITEM", "Copy link"].Find(3);
        save.Invoke();
        200.ms();
        var link = clipboardData.getText();
        print.it(link);
        string file = download + pathname.getName(link);
        try { internet.http.Get(link, file); }
        catch (Exception e1) { print.warning($"Failed to download. {e1.ToStringWithoutStack()}"); continue; }
        print.it("downloaded");
        
        //var w3 = wnd.find(20, "另存为", "#32770").Activate();
        //if (w3.Is0) continue;
        //var input = w3.Elm["WINDOW", "文件名:", "class=Edit"].Find(10);
        //200.ms();
        //var filename = input.Navigate("fi").Value;
        //200.ms();
        //keys.send("Ctrl+A", $"!{download + filename}");
        //100.ms();
        //keys.send("Enter");
        //var filepath = pathname.correctName(download + filename);
        //wait.forCondition(10, () => filesystem.exists(filepath));
        //if (filesystem.exists(filepath)) {
            
        //} else goto load;

        
        
    }
}


var folder = folders.Desktop + @"notes-box";
var a = filesystem.enumFiles(folder, "*.pdf", FEFlags.AllDescendants).ToArray();
dialog.show("Done", $"{a.Length} files has downloaded", secondsTimeout: 5);

/// <summary>
///
Opens a web page in Chrome or Edge, and waits until loaded.
/// </summary>
public class ChromePage {
    wnd _w;
    elm _eAddress, _eReload;
    
    //may need to change these strings. They may depend on your computer's language and browser program version.
    ///
    public static string AddressBarName = "Address and search bar";
    
    ///
    public static string ReloadButtonName = "**m Reload||Refresh"; //Chrome||Edge
    
    ///
    public static string ReloadButtonDescription = "**m Reload this page||Refresh (Ctrl+R)";
    
    /// <summary>
    ///
Finds UI elements for later opening a URL and waiting.
    /// </summary>
    ///
<param name="w">Chrome or Edge window.</param>
    public ChromePage(wnd w) {
        _w = w;
        var e = _w.Elm["TOOLBAR"].Find(1);
        _eAddress = e.Elm["TEXT", AddressBarName].Find(1);
        _eReload = e.Elm["BUTTON", ReloadButtonName].Find(1);
    }

    
    /// <summary>
    ///
Opens a web page and waits until loaded or stopped.
    /// Also activates the browser window and makes the address bar focused.
    /// </summary>
    ///
<param name="url">Web page URL.</param>
    ///
<param name="secondsTimeout">How long to wait until loaded. The same as with most other "wait for" functions of the automation library (0 infinite, negative no exception).</param>
    ///
<returns>false if timeout (when <i>secondsTimeout</i> negative).</returns>
    ///
<exception cref="TimeoutException"></exception>
    ///
<exception cref="Exception">Exceptions of used functions.</exception>
    public bool Open(string url, double secondsTimeout = 60) {
        wildex desc = ReloadButtonDescription;
        _w.Activate();
        _eAddress.Focus(); //must be before setting Value
        _eAddress.Value = url;
        _w.Send(0x100, (int)KKey.Enter); //WM_KEYDOWN
        _w.Send(0x101, (int)KKey.Enter); //WM_KEYUP
        100.ms();
        return wait.forCondition(secondsTimeout, () => desc.Match(_eReload.Description));
    }
}


Messages In This Thread
RE: Elm couldn't find popup download button - by birdywen - 06-21-2023, 02:13 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)