06-19-2023, 02:41 PM
Hi Dear Gintaras,
The line 22, Elm couldn't find the download button after waiting.
Please help!
Besides, the chrome waiting function is still very reliable after more thousands of testing and never failed.
one question, If I use invoke or web-invoke to click links on the chrome page(w), will be all the page wait until loaded or just the main page (p.open(url)) ? Thanks
The line 22, Elm couldn't find the download button after waiting.
Please help!
Besides, the chrome waiting function is still very reliable after more thousands of testing and never failed.
one question, If I use invoke or web-invoke to click links on the chrome page(w), will be all the page wait until loaded or just the main page (p.open(url)) ? Thanks
// script "Notes-box.com.cs"
//.
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.MediaStop, pauseKey: KKey.MediaPlayPause);
//..
var w = wnd.find(0, "* - Google Chrome", "Chrome_WidgetWin_1");
var p = new ChromePage(w);
p.Open("https://notes-box.com/notes/classical-music/");
200.ms();
for (int i = 1; i < 83; i++) {
p.Open($"https://notes-box.com/notes/classical-music/?PAGEN_1={i}");
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(1).Name;
var download = $@"C:\notes-box\classical\{composer}";
//filesystem.delete(download);
filesystem.createDirectory(download);
var click = w.Elm["web:GROUPING", prop: "@target=_blank"].Find(1);
click.Invoke();
100.ms();
var button = w.Elm["web:LINK", "DOWNLOAD FILE", new("@href=/upload/iblock/*.pdf\n", "@target=_blank")].Find(18);
//16.s();
200.ms();
button.Focus();
keys.send("Apps");
var w2 = wnd.find(5, "", "Chrome_WidgetWin_2","chrome.exe");
var save = w2.Elm["MENUITEM", "Save link as…"].Find(3);
save.Invoke();
300.ms();
var save1 = wnd.find(1, "另存为", "#32770");
var input = w.Elm["TEXT", "文件名:", "class=Edit"].Find(1);
input.SendKeys(download+input.Value);
200.ms();
script.debug();
Debugger.Break();}
}
/// <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));
}
}