[answered]AutoClic PowerShell RRS feed

  • Question

  • Hi everybody, 

    I will try speak english ^^

    I would like clic on the button for download the CSV file with PowerShell. ( The website it's Google Trends and URL file for download CSV expire in 1 day) 

    My code:

    $url = ""
    $ie = New-Object -com internetexplorer.application 
    $ie.visible = $true 
    while ($ie.Busy -eq $true) 
        Start-Sleep -Milliseconds 1000


    -I do not find the button ID


    Method invocation failed because [System.DBN
    At line:5 char:1
    + $ie.Document.getElementById("CSV").Click()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperati
        + FullyQualifiedErrorId : MethodNotFound

    Thank you :) 

    • Edited by Atlante21 Friday, August 17, 2018 2:05 PM
    Tuesday, August 7, 2018 8:39 PM

All replies

  • $buttons = $ie.Document.body.getElementsByTagName("button") | Where-Object { $_.title -eq "CSV" }

    I can see there are 4 different buttons that can export CSV on the URL you provided. Depending on which one you want to click:


    Also, you will have to handle saving the csv file, for instance like:

    $obj = New-Object -Com WScript.Shell
    $obj.AppActivate('technet - Explore - Google Trends - Internet Explorer')
    Start-Sleep -Seconds 1

    But, it would be much easier if you use the Developer Tools to capture the queries made to download the CSV file and replicate it with the Invoke-WebRequest PowerShell cmdlet. But you'll have to find out the parameters passed with the URL.

    Invoke-WebRequest -Uri "{%22time%22%3A%222018-08-07T19%5C%5C%3A42%5C%5C%3A30%202018-08-07T20%5C%5C%3A42%5C%5C%3A30%22,%22resolution%22%3A%22MINUTE%22,%22
    22%3A%22CM%22,%22category%22%3A0}}&token=APP6_UEAAAAAW2tVtlKPhenWmGKfjXl8j8rBuhO-DlJi&tz=-120" -OutFile C:\temp\stuff.csv

    Tuesday, August 7, 2018 9:12 PM
  • Ok thank you :) 
    Tuesday, August 7, 2018 9:24 PM
  • You're welcome. If your question has been answered, please don't forget to mark the thread as answered. It helps improve the chance of others with similar questions obtaining answers.

    Friday, August 17, 2018 12:09 PM