How to control Chrome Downloads page Using Selenium c

0 votes

I'm trying to manipulate "chrome://downloads/" URL using Selenium.

My objective is to

  • Start a download,
  • Make sure that download get start
  • Cancel the download

But the problem is that I´m not able to get the values of the downloads or cancel.

It shows an error:  that my id isn't correct. Does anyone know if there any restriction to this kind of page?

Below is my code:

using System;

using System.IO;

using System.Net;

using System.Net.Sockets;

using System.Text.RegularExpressions;

using System.Threading;

using OpenQA.Selenium.Chrome;

using OpenQA.Selenium.Firefox;

namespace SitesApplications

{

    class Program

    {

        static void Main(string[] args)

        {

           BrowseUrl.driver = new ChromeDriver();

            //ChromeOptions TESTE = new ChromeOptions();

            //TESTE.AddArgument("--disable-privacy");

            FileDownload teste = new FileDownload("https://img.cs.montana.edu/linux/centos/7.4.1708/isos/x86_64/", 60);


            teste.gotoDownloadList("chrome://downloads/", 60);


            //ChromeWebElement haha = new ChromeWebElement(BrowseUrl.DriverChrome, "pause-or-resume");


            ////haha.Clicks(20);


            //haha.Cliquei(20);


            teste.CancelaTeste(10);


        }


    }

Program Calls

using OpenQA.Selenium;

using OpenQA.Selenium.Support.PageObjects;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace SitesApplications

{

    class FileDownload

    {

        /// <summary>

        /// Enta no link direto para o download.

        /// </summary>

        /// <param name="Url">Link de destino para o download.</param>

        /// <param name="time">Tempo maximo para abertura da pagina.</param>

        public FileDownload(string Url, int time)

        {

            BrowseUrl CentOs = new BrowseUrl(Url, time);

            PageFactory.InitElements(BrowseUrl.driver, this);

        }


        public void gotoDownloadList(string url, int timeout)

        {


            BrowseUrl downList = new BrowseUrl(url, timeout);

            PageFactory.InitElements(BrowseUrl.driver, this);


        }


        private bool barra_prog;


        public bool barraprog

        {

            get { return barra_prog; }

May 7, 2018 in Selenium by Martin
• 4,320 points
9,772 views

1 answer to this question.

0 votes

In your case you must replace 'cancel' by 'Cancelar'.

Check this Question : Accessing Shadow DOM tree with Selenium

Read this article on Shadow DOM Elements here: http://www.seleniumeasy.com/selenium-tutorials/accessing-shadow-dom-elements-with-webdriver.To know how to handle the Chrome download page you must know how to handle Shadow DOM Elements. I tried a lot of different solutions before I finally managed to get the one below working:

 IJavaScriptExecutor jse2 = (IJavaScriptExecutor)Driver;

        jse2.ExecuteScript("return document.querySelector('downloads-manager').shadowRoot.querySelector('downloads-item').shadowRoot.getElementById('cancel').click()");

answered May 7, 2018 by Samarpit
• 5,910 points

Related Questions In Selenium

0 votes
2 answers

How to get a page name using Selenium Webdriver (C#)?

String pageTitlte=driver.getTitle(); READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
2,655 views
0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
18,973 views
0 votes
2 answers

How to open a browser window in full screen using Selenium WebDriver with C#

Hi , we have inbuilt method Maximize(). driver.Manage().Wind ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
16,119 views
+1 vote
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,776 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,188 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,265 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,902 views
0 votes
3 answers

How to set Page Load Timeout using C# using Selenium WebDriver

driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(15); READ MORE

answered Apr 17, 2019 in Selenium by Tim Muir
10,230 views
0 votes
1 answer

How to set Page Load Timeout using C# and Selenium Webdriver

Check this out C# WebDriver API now contains ...READ MORE

answered Aug 3, 2018 in Selenium by Samarpit
• 5,910 points
6,290 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP