Jump to content

WebDriver UDF - Help & Support


Recommended Posts

@damp

I solve my problem making delay  like following and after iall is working 

$sbutton= _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath,"//button[@id='action.save' and @name='action'  and @class='btn btn-md btn-primary col-md-3 pull-right']")
Local $test92 = _WD_ElementAction($sSession, $sbutton, 'click')
sleep(1000)

Thanks 
 

Link to comment
Share on other sites

#include <Array.au3>
#include 'wd_helper.au3'

$_WD_DEBUG = False
Global $sDesiredCapabilities
Global $sSession

_SetupIE()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

_Example()

Func _Example()
    _WD_Navigate($sSession, "https://docs.microsoft.com/en-us/windows/win32/controls/window-controls")

     $aTables = _WD_FindElement($sSession,"tag name", "table", '', True)
     if @error=0 then
        _ArrayDisplay($aTables)
     Else
        ConsoleWrite("@error=" & @error & @CRLF)
    EndIf
EndFunc

Func _SetupIE()
    _WD_Option('Driver', 'IEDriverServer.exe')
    _WD_Option('Port', 5555)
    _WD_Option('DriverParams', '--log-file=' & @ScriptDir & '\IE.log')
    $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
EndFunc   ;==>_SetupIE

An error occurred after running the above code, as follows:

_WDStartup: OS    : WIN_7 WIN32_NT 7601 Service Pack 1
_WDStartup: AutoIt: 3.3.14.2
_WDStartup: WD.au3: 0.1.0.19
_WDStartup: Driver: IEDriverServer.exe
_WDStartup: Params: --log-file=I:\IE.log
_WDStartup: Port  : 5555

__WD_Post: URL=HTTP://127.0.0.1:5555/session; $sData={"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}

__WD_Post: StatusCode=200; ResponseText={
    "value" : 
    {
        "capabilities" : 
        {
            "acceptInsecureCerts" : false,
            "browserName" : "internet explorer",
            "browserVersion" : "11",
            "pageLoadStrategy" : "normal",
            "platformName" : "windows",
            "proxy" : {},
            "se:ieOptions" : 
            {
                "browserAttachTimeout" : 0,
                "elementScrollBehavior" : 0,
                "enablePersistentHover" : true,
                "ie.browserCommand行.witches" : "",
                "ie.ensureCleanSession" : false,
                "ie.fileUploadDialogTimeout" : 3000,
                "ie.forceCreateProcessApi" : false,
                "ignoreProtectedModeSettings" : false,
                "ignoreZoomSetting" : false,
                "initialBrowserUrl" : "http://localhost:5555/",
                "nativeEvents" : true,
                "requireWindowFocus" : false
            },
            "setWindowRect" : true,
            "timeouts" : 
            {
                "implicit" : 0,
                "pageLoad" : 300000,
                "script" : 30000
            },
            "unhandledPromptBehavior" : "dismiss"
        },
        "sessionId" : "b8a652a9-be13-4ec2-8fa9-24a36795371a"
    }
}

_WD_CreateSession: {
    "value" : 
    {
        "capabilities" : 
        {
            "acceptInsecureCerts" : false,
            "browserName" : "internet explorer",
            "browserVersion" : "11",
            "pageLoadStrategy" : "normal",
            "platformName" : "windows",
            "proxy" : {},
            "se:ieOptions" : 
            {
                "browserAttachTimeout" : 0,
                "elementScrollBehavior" : 0,
                "enablePersistentHover" : true,
                "ie.browserCommand行.witches" : "",
                "ie.ensureCleanSession" : false,
                "ie.fileUploadDialogTimeout" : 3000,
                "ie.forceCreateProcessApi" : false,
                "ignoreProtectedModeSettings" : false,
                "ignoreZoomSetting" : false,
                "initialBrowserUrl" : "http://localhost:5555/",
                "nativeEvents" : true,
                "requireWindowFocus" : false
            },
            "setWindowRect" : true,
            "timeouts" : 
            {
                "implicit" : 0,
                "pageLoad" : 300000,
                "script" : 30000
            },
            "unhandledPromptBehavior" : "dismiss"
        },
        "sessionId" : "b8a652a9-be13-4ec2-8fa9-24a36795371a"
    }
}

__WD_Post: URL=HTTP://127.0.0.1:5555/session/b8a652a9-be13-4ec2-8fa9-24a36795371a/url; $sData={"url":"https://docs.microsoft.com/en-us/windows/win32/controls/window-controls"}

__WD_Post: StatusCode=200; ResponseText={
    "value" : null
}

_WD_Navigate: {
    "value" : null
}

__WD_Post: URL=HTTP://127.0.0.1:5555/session/b8a652a9-be13-4ec2-8fa9-24a36795371a/elements; $sData={"using":"tag name","value":"table"}

__WD_Post: StatusCode=404; ResponseText={
    "value" : 
    {
        "data" : null,
        "error" : "no such window",
        "message" : "Currently focused window has been closed.",
        "stacktrace" : ""
    }
}

[_WD_FindElement: {
    "value" : 
    {
        "data" : null,
        "error" : "no such window",
        "message" : "Currently focused window has been closed.",
        "stacktrace" : ""
    }
}]

@error=9

why?

thanks in advance!

Link to comment
Share on other sites

Dear @Danp2
I am new and I look forward to your support in this regard:
I saw the example in the demo file and it seems that it only has an example of WD_Action with mouse:
$sAction = '{"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"'
$sAction &= $sElement & '","' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}},{"button":2,"type":"pointerDown"},{"button":2,"type":"pointerUp"}]}]}'
I want to send the {pagedown} key in WD, what should I do?
Thank you!

Edited by nguyenthaiytcc
Link to comment
Share on other sites

How can i change the select option with the following sentence 

<div role="combobox" class="v-filterselect v-widget v-has-width" style="width: 20em;">

<input type="text" class="v-filterselect-input" autocomplete="nope" id="gwt-uid-3" aria-labelledby="gwt-uid-2" tabindex="0" dir="" style="width: 100%;">

<div class="v-filterselect-button" aria-hidden="true" role="button"></div></div>

My code 

$sTouche =_WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='gwt-uid-3']")
    _WD_ElementAction($sSession, $sTouche, 'property','')
_ChromeSetInputValueById($sSession,'gwt-uid-3','English')

And the debugger 

__WD_Post: URL=HTTP://127.0.0.1:9515/session/4ed0969e6701ee585ee758f05deb98f3/element; $sData={"using":"xpath","value":"//input[@id='gwt-uid-3']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"5472b4ed-0b82-4bf2-b75f-4fbde4f8a117"}}
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"5472b4ed-0b82-4bf2-b75f-4fbde4f8a117"}}
__WD_Get: URL=HTTP://127.0.0.1:9515/session/4ed0969e6701ee585ee758f05deb98f3/element/5472b4ed-0b82-4bf2-b75f-4fbde4f8a117/property/
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":null}...
_WD_ElementAction: {"value":null}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/4ed0969e6701ee585ee758f05deb98f3/element; $sData={"using":"xpath","value":"//input[@id='gwt-uid-3']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"5472b4ed-0b82-4bf2-b75f-4fbde4f8a117"}}
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"5472b4ed-0b82-4bf2-b75f-4fbde4f8a117"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/4ed0969e6701ee585ee758f05deb98f3/element/5472b4ed-0b82-4bf2-b75f-4fbde4f8a117/value; $sData={"id":"5472b4ed-0b82-4bf2-b75f-4fbde4f8a117", "text":"English"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ElementAction: {"value":null}...
+>15:21:34 AutoIt3.exe ended.rc:0
+>15:21:34 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 22.66

Beforei have "Deutsch" in the input and after i have DeutschEnglish in the fields 
 

Edited by loulou2522
Link to comment
Share on other sites

@nguyenthaiytcc This isn't something that I've needed to do previously, but I believe this would be the basic syntax --

$sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE00F"}, {"type": "keyUp", "value": "\uE00F"}]}]}'
_WD_Action($sSession, "actions", $sAction)

Please give it a try and report back with your results.

Link to comment
Share on other sites

@loulou2522 I suggest that you post a short reproducer that we can actually run to observe whatever issue you are encountering.

P.S. No idea what the 2nd line is supposed to be doing. If you are attempting to clear the prior value, this this would make more sense --

_WD_ElementAction($sSession, $sTouche, 'clear')

 

Link to comment
Share on other sites

$sSession = _WD_CreateSession($sDesiredCapabilities)
;_WD_Window($sSession, 'Maximize')
_WD_Navigate($sSession,"https://ubs-paymentstandards.ch/login")
Sleep(1000)

$sTouche =_WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='gwt-uid-3']")
    _WD_ElementAction($sSession, $sTouche, 'clear')
    Sleep(2000)
_ChromeSetInputValueById($sSession,'gwt-uid-3','English')

Sleep(1000)
exit

Here is the code to reproduce this case . Hope it will be suffisant for you to show the problem
 

Link to comment
Share on other sites

@loulou2522 This isn't a standard web element, so it takes multiple steps to accomplish your goal. The follow example will open the web page and then switch back and forth between English and Deutsch.

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

Local $sDesiredCapabilities
Local $sSession, $sElement, $sElement2

SetupChrome()
_WD_Startup()

If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession,"https://ubs-paymentstandards.ch/login")
Sleep(1000)

; Click arrow to open dropdown list
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='v-filterselect-button']")
_WD_ElementAction($sSession, $sElement, 'click')

; Wait for element to be present and then click it
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//span[contains(text(),'English')]", 1000)
$sElement2 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[contains(text(),'English')]")
_WD_ElementAction($sSession, $sElement2, 'click')

Sleep(2500)

; Click arrow to open dropdown list
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='v-filterselect-button']")
_WD_ElementAction($sSession, $sElement, 'click')

; Wait for element to be present and then click it
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//span[contains(text(),'Deutsch')]", 1000)
$sElement2 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[contains(text(),'Deutsch')]")
_WD_ElementAction($sSession, $sElement2, 'click')


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

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"excludeSwitches": ["enable-automation"]}}}}'
EndFunc

 

Link to comment
Share on other sites

15 hours ago, Chimp said:

hello @Letraindusoir, your code snippet works properly here, (win 7 x64 & ie 11) have you solved your problem?

Yes, I can now run it correctly by searching for relevant information. However, the IE browser needs to be set in advance.。

The Configuration Required are as follows:

Quote
  • On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
  • Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog.
  • The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
  • For Windows 10, you also need to set "Change the size of text, apps, and other items" to 100% in display settings.
  • For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...