Jump to content

WebDriver UDF - Help & Support


Recommended Posts

11 minutes ago, Danp2 said:

@BigDaddyO See prior discussion starting here --

I think My issue may be unique.  When inspecting the dropdown select box before selecting it, I see all the options.  but when I attempt to select one of those I get a message about not attached to the document.

I got around this by finding and clicking the dropdown select box, then doing the full find again and then clicking the option I want.

$eHIPPAtype = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[contains(@id,'callerTypeOptions') and not(contains(@id, 'callerTypeOptions1')) and contains(@class, 'callerTypeOptions')]")    ;Perform additional search for the field
_WD_ElementAction($sSession, $eHIPPAtype, "click")  ;Click the dropdown to get the list
sleep(1500)
$eHIPPAtypeMbr = _WD_FindElement($sSession,  $_WD_LOCATOR_ByXPath, "//select[contains(@id,'callerTypeOptions') and not(contains(@id, 'callerTypeOptions1')) and contains(@class, 'callerTypeOptions')]/option[contains(@value, 'Member')][1]")  ;find the first object that contains Member
_WD_ElementAction($sSession, $eHIPPAtypeMbr, "click") ;Click the item we want from the list

 

Link to comment
Share on other sites

Hi Danp2

I want before Navigate browser set my proxy ( ngocthang1.vpn.co:8899:ngocthang26:ngocthang26 ) and add ABP extension, I see you suggest 2 link for everyone
+ http://chromedriver.chromium.org/capabilities

+ http://chromedriver.chromium.org/extensions

But i don't know transfer to DesiredCapabilities, How do set proxy ? sorry i very bad code.

#include "wd_core.au3"
#include "wd_helper.au3"
Local $sDesiredCapabilities

$_WD_DEBUG = False


$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}'

SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.google.com/")
_WD_Window($sSession, 'maximize','')
;~ $hwnd = WinWaitActive("Google")
;~ WinSetState($hwnd, "", @SW_MAXIMIZE)
_WD_Action($sSession, "refresh")


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

Thanks you

Link to comment
Share on other sites

Hi @ngocthang26

I haven't personally had the need to do either of these actions, so I can't tell you exactly how to do this. If I get a chance, I'll try to check this out and report back with any findings.

In the mean time, you'll need to do what I would do in this case, which is to research and then use "trial and error" until you find a working scenario. The proxy subject came up once before in the main development thread. You may want to check out the links posted by @mLipok here.

 

Link to comment
Share on other sites

Hi @Danp2 I try very many code but don't set success Proxy.

$sDesiredCapabilities = '{"capabilities":{"chromeOptions": {"w3c": "true","browserName": "chrome", "args": ["disable-web-security"], "proxy": {"proxyType":"manual","httpProxy":"10.179.70.127:10801","sslProxy":"10.179.70.127:10801","autodetect": "false"}}}}'

You can try help me, i try link you sent but don't know transfer code.

 


 

Link to comment
Share on other sites

@ngocthang26 Have you tried it like this? Note that the proxy definition is outside of chromeOptions.

$sDesiredCapabilities = '{"capabilities":{"chromeOptions": {"w3c": "true"},"browserName": "chrome", "args": ["disable-web-security"], "proxy": {"proxyType":"manual","httpProxy":"10.179.70.127:10801","sslProxy":"10.179.70.127:10801","autodetect": "false"}}}'

Also, is that your actual IP address for the proxy or just something you pulled off the internet?

Link to comment
Share on other sites

DemoActions() part ... i didnt try anything :c im just trying to learn how to send keystrokes :c can you give me a code that send keystrokes to the active  element also im using both google chrome and firefox

 

Edited by Shogi
Link to comment
Share on other sites

I'm going to be running an automation as a Citrix Published app but I'm having all sorts of problems since each user is technically launching the same chromedriver.exe from a single box.

It seems to lock the .log files, so I switched that so it creates @UserName & ".log" but I also seem to be having a problem where each instance needs to use it's own port# but chromedriver doesn't seem to launch on anything but the 9515.

if I try any other port, the black window shows up but the website doesn't appear.  Again, I'm using my simple script for testing.

any ideas?

#include "wd_core.au3"
#include "wd_helper.au3"
;~ "explicitly-allowed-ports":9510,9511,9512.9513  ;comma seperated list of port number, port seems to be specified prior to the _WD_CreateSession so this isnt used.

FileInstall("Chromedriver.exe", @ScriptDir & "\Chromedriver.exe")
For $i = 1 to 30
    sleep(250)
    If FileExists(@ScriptDir & "\Chromedriver.exe") Then ExitLoop
Next

$sWebSite = "https://www.autoitscript.com/site/autoit/downloads/"
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "useAutomationExtension": false, "args":["start-maximized", "disable-infobars"] }}}}' ;Required to prevent Unpacked Extension error on servers

_SetupChrome()

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Timeouts($sSession, '{"type":"page load","ms":120000}')     ;Increase the default timeout.

_WD_Navigate($sSession, $sWebSite)

If _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//div/table[1]/tbody/tr/td[2]", 1000, 20000, True) <> 1 Then
    ConsoleWrite("Error, Item not found" & @CRLF)
    Exit
EndIf

$eDate = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div/table[1]/tbody/tr/td[2]")
$sDate = _WD_ElementAction($sSession, $eDate, "text")

MsgBox(0, "Date", "Date = " & $sDate & ".  Click OK to Exit")

_WD_DeleteSession($sSession)                        ;Close the chrome window
_WD_Shutdown()                                          ;Close the chromedriver.exe command window


Func _SetupChrome()

    If _WD_Option('Driver', 'chromedriver.exe') = 0 Then Return SetError(1)

;~  $iPort = _StartScan()
;~  If @error Then
;~      MsgBox(0, "Error", "Unable to find an open port")
;~      Exit
;~  EndIf
;~  If _WD_Option('Port', $iPort) = 0 Then Return SetError(1)   ;only 9515 is working, but this scanner doesnt see it as available!

    If _WD_Option('Port', 9510) = 0 Then Return SetError(1) ;only 9515 is working!

    If _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\' & @UserName & '.log"') = 0 Then Return SetError(1)

EndFunc   ;==>_SetupChrome





;Find Open Port, not sure if this will work for the port chromedriver wants
Func _StartScan($sIPScan = "127.0.0.1", $sPortStart = 9100, $sPortEnd = 65353)
    Opt('TCPTimeout', 50)       ;Set the timeout for the Port connection
    TCPStartup()
    Local $sSoketID
    Local $sTimeStart = TimerInit()
    For $p = $sPortStart To $sPortEnd
        ConsoleWrite("Scanning Port: " & $p  & @CRLF)
        $sSoketID = TCPConnect($sIPScan, $p)
        If $sSoketID > 0 Then
            ConsoleWrite("Found an open port ( " & $p & " )" & @CRLF)
            ExitLoop
        EndIf
    Next
    TCPShutdown()

    If $p >= $sPortEnd Then
        Return SetError(1)
    Else
        Return $sPortStart
    EndIf

EndFunc   ;==>_StartScan

 

Thanks,

Mike

Link to comment
Share on other sites

Change this --

If _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\' & @UserName & '.log"') = 0 Then Return SetError(1)

to --

If _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\' & @UserName & '.log"' & ' --port=<your port #>') = 0 Then Return SetError(1)

 

Link to comment
Share on other sites

thank you :) also why i cant send keyboard and pointer actions to google chrome using chromedriver?! i used this script to test 

#include <wd_core.au3>
#include <wd_helper.au3>
#include <Misc.au3>

$hDLL = DllOpen("user32.dll")

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

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}'

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

while 1
    if _IsPressed("73", $hDLL) then 
    _WD_Action($sSession, "actions", '{"actions": [{"type": "key","id": "keyboard","actions": [{"type": "KeyDown", "value": "a"},{"type": "sleep", "duration": 5},{"type": "Keyup", "value": "a"}]}]}')
    endif
wend

Console

__WD_Post: StatusCode=404; ResponseText={"value":{"error":"unknown command","message":"(Session infochrome=69.0.3497.100)","stacktrace":"Backtrace:\n\tOrdinal0 [0x009EAA90+830096]\n\tOrdinal0 [0x0099581D+481309]\n\tOrdinal0 [0x0096A9F1+305649]\n\tOrdinal0 [0x009500D0+196816]\n\tOrdinal0 [0x0094AA77+174711]\n\tOrdinal0 [0x00932D54+77140]\n\tOrdinal0 [0x0093430C+82700]\n\tOrdinal0 [0x00934260+82528]\n\tOrdinal0 [0x009F5302+873218]\n\tOrdinal0 [0x009A0553+525651]\n\tOrdinal0 [0x009A0783+526211]\n\tOrdinal0 [0x009A086C+526444]\n\tOrdinal0 [0x009F83A7+885671]\n\tOrdinal0 [0x009A03BF+525247]\n\tOrdinal0 [0x009AA60E+566798]\n\tOrdinal0 [0x009B5DDB+613851]\n\tOrdinal0 [0x009B5F45+614213]\n\tOrdinal0 [0x009B5175+610677]\n\tBaseThreadInitThunk [0x76318484+36]\n\tRtlValidSecurityDescriptor [0x77AD305A+282]\n\tRtlValidSecurityDescriptor [0x77AD302A+234]\n"}}
_WD_Action: {"value":{"error":"unknown command","message":"(Session infochrome=69.0.3497.100)","stacktrace":"Backtrace:\n\tOrdinal0 [0x009EAA90+830096]\n\tOrdinal0 [0x0099581D+481309]\n\tOrdinal0 [0x0096A9F1+305649]\n\tOrdinal0 [0x009500D0+196816]\n\tOrdinal0 [0x0094AA77+174711]\n\tOrdinal0 [0x00932D54+77140]\n\tOrdinal0 [0x0093430C+82700]\n\tOrdinal0 [0x00934260+82528]\n\tOrdinal0 [0x009F5302+873218]\n\tOrdinal0 [0x009A0553+525651]\n\tOrdinal0 [0x009A0783+526211]\n\tOrdinal0 [0x009A086C+526444]\n\tOrdinal0 [0x009F83A7+885671]\n\tOrdinal0 [0x009A03BF+525247]\n\tOrdinal0 [0x009AA60E+566798]\n\tOrdinal0 [0x009B5DDB+613851]\n\tOrdinal0 [0x009B5F45+614213]\n\tOrdinal0 [0x009B5175+610677]\n\tBaseThreadInitThunk [0x76318484+36]\n\tRtlValidSecurityDescriptor [0x77AD305A+282]\n\tRtlValidSecurityDescriptor [0x77AD302A+234]\n"}}
Edited by Shogi
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...