Jump to content

Recommended Posts

Posted

 

Hello,

can I use _WinINet_GetUrlCacheEntryInfoEx function to download files while using Webdriver, this was working when use IE browser and I have switiched to Edge browser using Web driver, now its not happening, can anyone fix this or suggest best way to download files to customized folder  

 

$aUrlPs = 'https://ViewDocData?gdcustorgid=AT5672TDMLTCBGXFZ3W5XVEXTM&archid=IE6DEDFNKDZXSPRJ4V35JEQ4LE'
    _WD_Navigate($Session, $aUrlPs)
    _WD_LoadWait($Session, 500)


    $sPO = 'D6KO40A'

    $iPdf = @ScriptDir & '\' & $sPO & '.pdf'

    Sleep(2000)
    Local $j = 0
    While 1
        Local $HttPArray = _WinINet_GetUrlCacheEntryInfoEx($aUrlPs)

        If Not @error Then
            Local $fPDF = StringStripWS($HttPArray[2], 3)
            If StringInStr($fPDF, '.pdf') > 0 And FileExists($fPDF) = 1 Then
                FileCopy($fPDF, $iPdf, 1)
                ExitLoop
            EndIf
        Else
            Sleep(500)
            $j = $j + 1
        EndIft

        If $j = 20 Then
            $iErrorNote = 'DO Issued | Unable to download.'
            ExitLoop
        EndIf
    WEnd
 

Posted (edited)
  On 3/3/2023 at 1:37 PM, RohanM said:

$aUrlPs = 'https://ViewDocData?gdcustorgid=AT5672TDMLTCBGXFZ3W5XVEXTM&archid=IE6DEDFNKDZXSPRJ4V35JEQ4LE'
    _WD_Navigate($Session, $aUrlPs)
    _WD_LoadWait($Session, 500)

Expand  

When run only this small part of the script, is it starting to download file ?

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Hi @Danp2 yes I have used _WD_DownoadFile function but its not getting download full file if I download the file manually file size is 35KB but using function file size is 30KB and downloaded file not able to open.

  

$aUrlPs = 'https://network.infornexus.com/servlet/GDCViewDocData?gdcustorgid=AT5672TDMLTCBGXFZ3W5XVEXTM&archid=HFZOM5JQYGR7XUPDB6PTJMXDZU'

$sPO = 'D6KO40A'

$iPdf = @ScriptDir & '\' & $sPO & '.pdf'

_WD_DownloadFile($aUrlPs, $iPdf, 0)

 

Posted

Hi @mLipok

yes, if execute below lines, the PDF document will be open in the Edge browser, but it will not start automatically download option. 

$aUrlPs = 'https://ViewDocData?gdcustorgid=AT5672TDMLTCBGXFZ3W5XVEXTM&archid=IE6DEDFNKDZXSPRJ4V35JEQ4LE'
    _WD_Navigate($Session, $aUrlPs)
    _WD_LoadWait($Session, 500)

 

Posted (edited)
  On 3/6/2023 at 5:54 AM, RohanM said:

yes, if execute below lines, the PDF document will be open in the Edge browser, but it will not start automatically download option. 

Expand  

this is kind of settings, maybe in Capabilities will take a look if I have hit the problem before let me check.....

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

As a basic try this

 

Func DownloadPDFFile($fileURL, $downloadPath)
    ; Start the WebDriver session
    Local $sDriverPath = "C:\webdriver\chromedriver.exe" ; replace with your webdriver path
    _WD_Startup()
    Local $sSession = _WD_CreateSession("chrome", $WD_FLAG_LOCAL)

    ; Navigate to the file download URL
    _WD_Navigate($sSession, $fileURL)

    ; Wait for the file to download
    Local $bDownloaded = False
    Local $iTimeout = 30
    While $iTimeout > 0 And Not $bDownloaded
        Sleep(1000)
        $iTimeout -= 1
        If _FileCountLines($downloadPath & "\filename.pdf") > 0 Then
            $bDownloaded = True
        EndIf
    WEnd

    ; Quit the WebDriver session
    _WD_Close($sSession)
    _WD_Shutdown()

    ; Return the downloaded file path
    Return $downloadPath & "\filename.pdf"
EndFunc

 

Posted
  On 3/6/2023 at 9:13 AM, Cyborg5000 said:

_WD_CreateSession("chrome", $WD_FLAG_LOCAL)

Expand  

Did you test it ? As far as I know it will fail.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 3/6/2023 at 8:58 AM, mLipok said:

this is kind of settings, maybe in Capabilities will take a look if I have hit the problem before let me check.....

Expand  

@RohanM try my settings:

_WD_CapabilitiesAdd('firstMatch', 'chrome')
        _WD_CapabilitiesAdd('browserName', 'chrome')
        _WD_CapabilitiesAdd('w3c', True)
        _WD_CapabilitiesAdd('args', 'user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win' & StringReplace(@OSArch, 'X', '') & '; ' & @CPUArch & ') AppleWebKit/537.36 (KHTML, like Gecko) Chrome/' & _WD_GetBrowserVersion('chrome') & ' Safari/537.36')
        _WD_CapabilitiesAdd('args', 'user-data-dir', $s_Browser_Profile_Dir)
        _WD_CapabilitiesAdd('args', '--profile-directory', Default)
        _WD_CapabilitiesAdd('args', 'start-maximized')
        _WD_CapabilitiesAdd('args', 'disable-infobars')
        _WD_CapabilitiesAdd('args', '--no-sandbox')
        _WD_CapabilitiesAdd('args', '--disable-blink-features=AutomationControlled')
        _WD_CapabilitiesAdd('args', '--disable-web-security')
        _WD_CapabilitiesAdd('args', '--allow-running-insecure-content') ; https://stackoverflow.com/a/60409220
        _WD_CapabilitiesAdd('args', '--ignore-certificate-errors') ; https://stackoverflow.com/a/60409220
        _WD_CapabilitiesAdd('args', '--guest')

        _WD_CapabilitiesAdd('prefs', 'credentials_enable_service', False) ; https://www.autoitscript.com/forum/topic/191990-webdriver-udf-w3c-compliant-version-12272021/?do=findComment&comment=1464829
        _WD_CapabilitiesAdd('prefs', 'download.default_directory', $s_Download_dir)

        _WD_CapabilitiesAdd('excludeSwitches', 'disable-popup-blocking') ; https://help.applitools.com/hc/en-us/articles/360007189411--Chrome-is-being-controlled-by-automated-test-software-notification
        _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
        _WD_CapabilitiesAdd('excludeSwitches', 'enable-logging')
        _WD_CapabilitiesAdd('excludeSwitches', 'load-extension')

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Hi @mLipok

I am not sure that I am doing right here, but after Navigating the URL I have call the _WD_DownloadFile with same URL and it did the trick for me.

 

    $DocUrlPdf = 'https://net.info.com/' & StringReplace($artHis[1], 'amp;', '')
    _WD_Navigate($Session, $DocUrlPdf)
    _WD_LoadWait($Session, 500)

    $iPdf = @ScriptDir & '\DownloadFiles\' & $sPO & '.pdf'

  _WD_DownloadFile($DocUrlPdf, $iPdf, 0)

Posted
  On 3/6/2023 at 9:42 AM, RohanM said:

after Navigating the URL I have call the _WD_DownloadFile with same URL and it did the trick for me.

Expand  

good for you :)

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

here:
https://scripteverything.com/download-pdf-selenium-python/

I found this:

  Quote

from selenium.webdriver import Chrome, ChromeOptions


options = ChromeOptions()
chrome_prefs = {
    "download.prompt_for_download": False,
    "plugins.always_open_pdf_externally": True,
    "download.open_pdf_in_system_reader": False,
    "profile.default_content_settings.popups": 0,
}
options.add_experimental_option("prefs", chrome_prefs)

Expand  

I think that we can do the same

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 3/6/2023 at 10:06 AM, mLipok said:

here:
https://scripteverything.com/download-pdf-selenium-python/

I found this:

I think that we can do the same

Expand  

@RohanM Just try this:

#Region - downloading files
        ; https://scripteverything.com/download-pdf-selenium-python/
        ; https://www.autoitscript.com/forum/topic/209816-download-pdf-file-while-using-webdriver/?do=findComment&comment=1514582
        _WD_CapabilitiesAdd('prefs', 'download.prompt_for_download', False)
        _WD_CapabilitiesAdd('prefs', 'download.open_pdf_in_system_reader', False)
        _WD_CapabilitiesAdd('prefs', 'plugins.always_open_pdf_externally', True)
        _WD_CapabilitiesAdd('prefs', 'profile.default_content_settings.popups', 0)
        #EndRegion - downloading files

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...