Jump to content

Recommended Posts

Posted

Sorry to keep hijacking your thread, but how? I've only done this with Run($sCmd, "", Default, $STDOUT_CHILD) before

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Posted (edited)

Compile your WebDriver script and use this one for grabbing the console :

#include <Constants.au3>

$pid = Run ("Test.exe", "", @SW_SHOW, $STDERR_MERGED)
ProcessWaitClose ($pid)
$sText = StdoutRead ($pid)
MsgBox ($MB_SYSTEMMODAL,"",$sText)

Works for me.

 

Edited by Nine
Posted

I have been reworking a Internet Explorer automation to use Chrome. Sofar I have been working 2 days to finally start understanding how to get Webdriver UDF to work.
Basically I use the script to log into the website, so the user does not have to do it and also I do not have to provide everyone with the password everytime.

Using the the Webdriver UDF, I noticed the following Dos box everytime I run the script.
Could the chromedriver,exe be run silently, to make the automation less intrusive to my users ?

image.thumb.png.a5e622166d220b9ad1c1efef85df8750.png

 

After some hours the website, times outm so the script has to logon again. In my original IE script, I solved this the following way:

  1. Check if the one of the IE instances of the websote was "active"
  2. Refresh the website, if the URL changed to the login page, close the session and do a complete new login

With the webdriver UDF, I dont know how to check if an instance of the website is opened.
SO does anyone know how I could (with webdriver UDF):

  1. check if any chrome instance or tab has the page opended
  2. focus on that page
  3. refresh the page (I could then check the URL with  _WD_Action($sSession, 'url')
  4. if page needs login, then close the chrome instance or tab
  5. reopen the page and login or just get the focus to the instance/tab so the user can use this

Any hints how to proceed would be very helpful. TIA.

Posted

@Danp2

I have just looked at the FAQ, however chromedriver is only found 5 times in the FAQ with nothing pointing to how to run the chromedriver silently.
The word "silent" does not even appear in the FAQ. 
CORRECTION: Just found " How to hide the webdriver console" in the FAQ.  May be adding some keywords like DOSbox, silent, surpreess would make it easier to find this 😁

About _WD_Attach, I think I could work with that, by:

  1. try to attach to an URL or Title and check if there is a match
  2. no match: open new page
  3. match: refresh and check if user is still logged into the page, if not, do a re-login of the user

Have not tested the above yet, but will check how this tonight and tommorow.

Thanks for your input!

Posted

When I open a Chrome page manually and then create a session with autoit and do a _WD_Attach it will fail.
Also the moment I do an _WD_Shutdown, the Chrome session I created is gone, so it seems I must just exit the autoitscript without any cleanup.
When the autoit script exits and I try again, sometimes running the script again won't work, also sometimes an chrome.exe DOS box keeps popping up every x minutes....

I have to do more testing to find out why things are behaving like I this....
My overall thoughts are: nice to have an univeral way to automate webbrowsers, however the way it has been put together is definitely not easy! 😁

Posted
2 hours ago, Jemboy said:

When I open a Chrome page manually and then create a session with autoit and do a _WD_Attach it will fail.

IIRC, you can't use Webdriver to attach to a previously open instance of Chrome. Therefore, it makes sense to me that it doesn't work as posted. If I've misunderstood, please post a short script that demonstrates the issue.

Quote

Also the moment I do an _WD_Shutdown, the Chrome session I created is gone, so it seems I must just exit the autoitscript without any cleanup.

Not sure that I follow. Are you calling _WD_DeleteSession first? Show us your code so that we can see what you are attempting to do.

Quote

When the autoit script exits and I try again, sometimes running the script again won't work, also sometimes an chrome.exe DOS box keeps popping up every x minutes....

"Won't work" doesn't give us enough details to understand the issue. Show us the results from the Scite console for a failed attempt to run,

FWIW, I do most of my testing with Firefox, but I do recall seeing the situation where the DOS box keeps reappearing with Chrome. More testing will need to be done to determine if this is due to something with this UDF.

Quote

My overall thoughts are: nice to have an univeral way to automate webbrowsers, however the way it has been put together is definitely not easy! 😁

Imagine how difficult it would be if this UDF library didn't exist. 😜

On a more serious note, I appreciate the feedback and I'm open to suggestions which would help improve the UDF.

Posted

At the moment I kill chromedrive.exe before starting using _SetupChrome and _WD_Start.
I also do this afterwards to leave the created Chrome windows enabled.

Running my scriptt a second time without killing chromedriver.exe, will let my script fail due to chromedrive.exe running.
For now this is OK with me.

Does anyone know how to disable the chromedriver.exe to create a logfile?
I have removed --verbose, added --silent to the _WD_Option('DriverParams',... but to no avail.

Posted

Need expert advice here. I am not able to select value from drop down. Am I missing something?

 

Local Const $CTRL_INPUT_list = "//select[@id='servicelink']"

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $CTRL_INPUT_list)

$sRet = _WD_ElementAction($sSession, $sElement, "My Fav option")

Posted

Thank you @Danp2 for solving my previous issue.

#include "wd_core.au3"
#include "wd_helper.au3"
#include "WinHttp.au3"

Local $sDesiredCapabilities, $sSession, $sElement, $aElements, $sButton

_WD_Attach($sSession, "Login to TradeLink" )

$sSession = _WD_CreateSession($sDesiredCapabilities)

Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log trace --connect-existing')
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized"]}}}}'
EndFunc

Need help with WD_Attach. Want to use and automate the existing chrome window but not able to. 

Thanks in advance 

 

 

Posted

@hemal I can see several issues with your script as written --

  • Not a big deal, but you shouldn't need to include winhttp.au3
  • You can't call _WD_Attach before $sSession contains a valid session ID
  • I don't believe that you can connect to an existing instance of Chrome, so your attempt to use "--connect-existing" will likely be ignored or will generate an error condition
Posted
_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')

The example I grabbed the forum used a function SetupChrome() with the above line, this resulted in logging webdriver data to chrome.log with every run.
In my production enviroment, I wanted to disable this logging . Replacing just removing the path, so the webdriver won't know were to write the log file was enough.
Other options likereplacing --verbose by --silent  or , --disable-logging did not work.

_WD_Option('DriverParams', '')

 

Posted (edited)

@Danp2The code below is an example script (using the webdriver for Chrome).
This code will run everytime and also create a "Chrome" session everytime it is executed.
Because the script automates the login for users (so the user does not have to login manually), I can not delete the session (_WD_DeleteSession($sSession) ) or do a (_WD_Shutdown() ).
So I have to kill the chromedriver.exe at the end of the script. 
If I do not kill the chromedriver.exe the script will not run correctly a second time even if I kill the "chromedrive.exe" after the "bad" execute.
 

#include "wd_core.au3"
#include "wd_helper.au3"
#include <Array.au3>

$_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error

Local $sDesiredCapabilities, $sSession, $sElement
Local $sEmailAddress = 'admin@yourstore.com'
Local $sPassword = 'admin'
Global $sTitle = "NopCommerce Demo v1.0"

;Script needs chromedriver.exe, install if not present!
If not FileExists (@ScriptDir & "\chromedriver.exe") then
    Beep (500,1000)
    $ResFI = FileInstall (".\chromedriver.exe",@ScriptDir & "\",$FC_NOOVERWRITE)
    If $ResFI=0 Then
        MsgBox (262144,$sTitle,"Error: Could not install Chromedriver.exe nodig!")
        Exit
    EndIf
EndIf


; Check if Chromedriver.exe is active, and ask to kill ?
Local $aProcessList = ProcessList("chromedriver.exe")
If $aProcessList[0][0]>0 Then
    $CDMesaj = "Chromedriver.exe is still active." & @CRLF & "Do you want to close Chromedriver?"
    $Answ = MsgBox (262144 + $MB_YESNO,$sTitle,$CDMesaj)
    If $Answ = $IDYES  Then
        KillChromeDriver ()      ; Kill Chromedriver
    Else
        MsgBox (262144,$sTitle,"You selecte 'No', so chromedriver.exe is still active!")
        Exit
    EndIf
EndIf

SetupChrome()
$ResSU = _WD_Startup()
$ResSUE = @error
If $ResSU=0 then MsgBox (262144,$sTitle,"Result Startup = " &  $ResSU & "   " & "Error = " & $ResSUE)



SplashTextOn($sTitle, "Starting NopCommerce autologin wrapper script." & @CRLF & @CRLF & "This will take several seconds...", -1, 250, -1, -1, $DLG_TEXTLEFT, "", 24)
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Window($sSession, 'maximize')                   ;maximize the webdriver "Chrome window"
_WD_Navigate($sSession, "https://admin-demo.nopcommerce.com/login?")
_WD_LoadWait($sSession)
SplashOff()


$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='Email']")
_WD_ElementAction($sSession, $sElement, 'clear')
_WD_ElementAction($sSession, $sElement, 'value', $sEmailAddress)
_WD_LoadWait($sSession,1000)


$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='Password']")
_WD_ElementAction($sSession, $sElement, 'clear')
_WD_ElementAction($sSession, $sElement, 'value', $sPassword)
_WD_LoadWait($sSession,1000)


$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='button-1 login-button']")
_WD_ElementAction($sSession, $sElement, 'click')
_WD_LoadWait($sSession,2000)


 $CurURL = _WD_Action($sSession, 'url')
 ;MsgBox (262144,$sTitle,"URL = " &  $CurURL)
 If $CurURL <>"https://admin-demo.nopcommerce.com/admin/" Then
    MsgBox (262144,$sTitle,"NopCommerce demo login failed." & @CRLF & "Please try again!" & @CRLF & @CRLF & "if the problem persists, then contact your IT Wizard.!")
    KillChromeDriver ()
    Exit
EndIf


;_WD_DeleteSession($sSession)
;If @error Then Exit SetError(6, @error)
;_WD_Shutdown()


KillChromeDriver ()             ; Kill Chromedriver

Func KillChromeDriver()             ; Kill Chromedriver.exe
    ;Exit
    Local $aProcessList = ProcessList("chromedriver.exe")
    For $i = 1 To $aProcessList[0][0]
        ProcessClose($aProcessList[$i][1])
    Next
EndFunc


Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false,"prefs": {"credentials_enable_service": false}}}}}'
EndFunc

 

 

 

Edited by Jemboy
Posted
3 hours ago, Jemboy said:

_WD_Option('DriverParams', '')

This line can be dropped all together since this option defaults to a blank string

Quote

I do not kill the chromedriver.exe the script will not run correctly a second time even if I kill the "chromedrive.exe" after the "bad" execute.

Instead of killing chromedriver, you should try saving the session ID and then reusing it on subsequent runs of the script.

Posted

@hemal See if this works for you to reattach to an previous instance of Chrome --

#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities, $sSession, $sElement, $oJSON, $oCaps, $sDebugger

SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "http://google.com")

$oJSON = Json_Decode($_WD_SESSION_DETAILS)
$oCaps = Json_Get($oJSON, "[value][capabilities]")
$sDebugger = $oCaps.Item('goog:chromeOptions').Item('debuggerAddress')
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"debuggerAddress": "' & $sDebugger & '"}}}}'

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "http://yahoo.com")

Func SetupChrome()
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}'
EndFunc

P.S. I know about the Chrome "console" window that pops up, but haven't had time to investigate further

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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