Environment is C# and WinForms. I am trying to run a program that will create an image download element in an already created website. I am using WebView2 as the browser. I changed the for-loop to 2 iterations just to debug this issue. I can download 1 image successfully but my result is maxed out at 1 iteration. Thanks for any help! Below is the code giving me issues:
async void multiplePics (int column) => await webView2.ExecuteScriptAsync("" +
"var downloadElement=document.createElement('a'); " +
"downloadElement.setAttribute('download',''); " +
"downloadElement.href= document.getElementsByClassName('slick-slide slick-cloned')[" + column + "].getElementsByClassName('item')[0].getAttribute('href'); " +
"document.body.appendChild(downloadElement); " +
"downloadElement.click();" +
"downloadElement.remove(); " +
"");
for (int i = 0; i <= 1; i++)
{
Debug.WriteLine(i);
multiplePics( i);
}
have tried:
async private void button5_Click(object sender, EventArgs e)
{
void multiplePics(int column) {
//webView2.ExecuteScriptAsync( "javascript");
}
for (int i = 0; i <= 1; i++)
{await multiplePics(i);}
}
have also tried:
private void button5_Click(object sender, EventArgs e)
{
Task<string> multiplePics(int column) {
//return webView2.ExecuteScriptAsync( "javascript");
}
Task.Run( ()=>{ return multiplePics(0);} );
Task.Run( ()=>{ return multiplePics(1);} );
//tried GetAwaiter() along with GetResult() also
}
another attempt:
private async void button5_Click(object sender, EventArgs e)
{
//tried public & private async Task multiplePics with no success
//async Task multiplePics had no errors but had the same result
private async Task multiplePics(int column) =>
await webView2.ExecuteScriptAsync("" +
"var downloadElement=document.createElement('a'); " +
"downloadElement.setAttribute('download',''); " +
"downloadElement.href= document.getElementsByClassName('slick-slide slick-cloned')[" + column + "].getElementsByClassName('item')[0].getAttribute('href'); " +
"document.body.appendChild(downloadElement); " +
"downloadElement.click();" +
"downloadElement.remove(); " +
"");
for (int i = 0; i <= 3; i++)
{
await multiplePics(i);
}
}