Jump to content

WebDriver UDF - Help & Support (III)


Recommended Posts

  • Replies 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

@MarluyYour xpath needs to point to the desired Option element. Try this -- _WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='country']//option[@value='BRAZIL']")  

As the WebDriver UDF - Help & Support thread has grown too big, I started a new one. The prior thread can be found here.

https://developer.mozilla.org/en-US/docs/Web/API/Window/open#window_features Edit: It's often helpful to check out the internal code... in this case it's nice because it is passed to _WD_ExecuteS

Posted Images

IE is about to be shutting down and in my company, every Website that can't be run on Mozilla will be run on Edge on IE mode. So i gotta find a way to manipulate Edge on IE mode and that's not possible with IE UDF unfortunatly

Link to post
Share on other sites

Hi again,

I think i'm getting closer !

I'm trying with IERDriverServer :

_WD_Option('Driver', @ScriptDir & '\include\' & (@Compiled ? '' : 'Exe_externe\') & 'IEDriverServer.exe')
_WD_Option('DriverParams', '--log trace ')
_WD_Option('Port', 5555)
Local $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"se:ieOptions": { "ie.edgechromium":true, "ie.edgepath":"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"}}}}'

But now i get this error in the console :

Quote

_WD_CreateSession: {
    "value" :
    {
        "error" : "session not created",
        "message" : "Unexpected error launching Internet Explorer. CreateProcess() failed for edge with the following command: msedge.exe --ie-mode-force --internet-explorer-integration=iemode --user-data-dir=C:\\Users\\JOUGLE~1\\AppData\\Local\\Temp\\IEDriver-0a0bc4ed-54ca-4b71-84bf-7d2c4ebcf5c9 --no-first-run --no-service-autorun --disable-sync --disable-features=msImplicitSignin http://localhost:5555/",
        "stacktrace" : ""
    }
}

I have no idea what to think about this error message, if anyone has an idea i would be grateful !

Link to post
Share on other sites
Quote

Where did you come up with these?

From reading forums and example in Java, i knew i had to edit those 2 options in order to get EDGE run instead of IE, i just didn't know how to do it in Autoit. Then while i was trying random way to do it, i got the structure in the console :

_WD_CreateSession: {
    "value" :Unexpected error launching Internet Explorer. CreateProcess() failed for edge with the following command 
    {
        "capabilities" : 
        {
            "acceptInsecureCerts" : false,
            "browserName" : "internet explorer",
            "browserVersion" : "11",
            "pageLoadStrategy" : "normal",
            "platformName" : "windows",
            "proxy" : {},
            "se:ieOptions" : 
            {
                "browserAttachTimeout" : 0,
                "elementScrollBehavior" : 0,
                "enablePersistentHover" : true,
                "ie.browserCommandLineSwitches" : "",
                "ie.edgechromium" : false,
                "ie.edgepath" : "",
                "ie.ensureCleanSession" : false,
                "ie.fileUploadDialogTimeout" : 3000,
                "ie.forceCreateProcessApi" : false,
                "ignoreProtectedModeSettings" : false,
                "ignoreZoomSetting" : false,
                "initialBrowserUrl" : "http://localhost:5555/",
                "nativeEvents" : true,
                "requireWindowFocus" : false
            },
            "setWindowRect" : true,
            "strictFileInteractability" : false,
            "timeouts" : 
            {
                "implicit" : 0,
                "pageLoad" : 300000,
                "script" : 30000
            },
            "unhandledPromptBehavior" : "dismiss and notify"
        },
        "sessionId" : "6d10a485-493d-4176-ac62-3e5f29447b50"
    }
}

From then i managed to open Edge by edited those 2 options as mentioned above.

 

It's now working, i had to double the blackslah of my edge path option. The correct code is :

_WD_Option('Driver', @ScriptDir & '\include\' & (@Compiled ? '' : 'Exe_externe\') & 'IEDriverServer.exe')
    _WD_Option('DriverParams', '--log trace ')
    _WD_Option('Port', 5555)
    Local $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": { "se:ieOptions" : { "ie.edgepath":"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe", "ie.edgechromium":true, "ignoreProtectedModeSettings":true }}}}'

    $iWDPid = _WD_Startup()
    $sWDSession = _WD_CreateSession($sDesiredCapabilities)

Thanks for the help !

Link to post
Share on other sites

Going forward on my project to pilote an IE mode Edge browser, i got another problem. It looks like WebDriver functions are not working well with IEDriverServer and even some of them are considered as unknown command.

See bellow, the result when i'm trying to locate an element by name :

_WD_GetElementByName($sWDSession, "nir") ==> Console :

__WD_Post ==> Webdriver Exception: {
	"value" : 
	{
		"error" : "invalid selector",
		"message" : "Unable to locate an element with the xpath expression //*[@name=\"nir\"] because of the following error:\nTypeError"
    	"stacktrace" : ""
    }
}

When i'm trying to edit an input :

_WD_SetElementValue($sWDSession, $hNir, $sNir) ==> console :
 
 _WD_ElementAction ==> Unknown Command: {
    "value" : 
    {
        "error" : "unknown command",
        "message" : "Command not found: POST /session/b7e28baf-19bf-43d3-8ff2-7cfa79c51a14/element/value",
        "stacktrace" : ""
    }
}

 

Any idea ?

Link to post
Share on other sites

@KerasI'm not sure why it wouldn't like that xpath since AFAIK the other major webdrivers all accept it without any issues. If you take a look at the code for _WD_GetElementByName, you will see that it is just a wrapper for _WD_FindElement. You will need to experiment to find an xpath that works with this driver and then report back.

I'm not sure what's happening as far as _WD_SetElementValue. Does this happen with all webdrivers or just IEDriver? What are the contents of $hNir and $sNir?

Link to post
Share on other sites

@Danp2I tried with CSSSelector strategy instead of Xpath and it worked for _WD_FindElement. I'll have to experiment a bit more to find out why it haven't worked with Xpath strategy.

Regarding _WD_SetElementValue, it was maybe not working because $hNir was the handle returned by _WD_GetElementByName which resulted into an error. With the CSSSelector method, _WD_SelEmentValue is working a little bit. It sets the value on the input, but it does it really slowly, like 1 character each 2 secondes and it end up with a timed out :

__WD_Post: URL=HTTP://127.0.0.1:5555/session/156e8b6e-f483-4f52-9606-dd4370257d1e/element/6c4decdb-bc31-4f8a-9262-716d440be3a3/value; $sData={"id":"6c4decdb-bc31-4f8a-9262-716d440be3a3", "text":"1971159606364"}
__WD_Post: StatusCode=0; ResponseText=WinHTTP request timed out before Webdriver...
__WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_ElementAction: WinHTTP request timed out before Webdriver...
_WD_ElementAction ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_SetElementValue ==> Send / Recv error

 

Link to post
Share on other sites

@Danp2I hope so. There is still the message :

"Turn off remote debugging to open this site in IE mode otherwise it might not work as expected."

I saw there that they had once the same issue on IE driver and it got patched. I'll see if i can ask for the same for MSEdge driver 🙏.

Link to post
Share on other sites

Fixed the (very very) slow part of InternetExplorerDriver WebDriver by replacing IEDriverServer.exe (switched from x64 version to x32 version). Everything is good now !

Thanks for help !

Link to post
Share on other sites
51 minutes ago, Keras said:

Fixed the (very very) slow part of InternetExplorerDriver WebDriver by replacing IEDriverServer.exe (switched from x64 version to x32 version). Everything is good now !

Please share to us full working example.

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 for other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2022-03-07

Link to post
Share on other sites

@mLipok Yep :
 

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

Global $sUrlExample = "https://getbootstrap.com/docs/4.0/components/forms/"

_Setup_IEDriver()

Global $sWDSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sWDSession, $sUrlExemple)
_WD_LoadWait($sWDSession)
_form_example("Test@test.fr", "azerty123456")

Func _form_example($sEmail, $sPassword)
    Local $sEmailInput = _WD_GetElementByID($sWDSession, "exampleInputEmail1")
    _WD_ElementAction($sWDSession, $sEmailInput, "VALUE", $sEmail)

    Local $sPasswordInput = _WD_GetElementByID($sWDSession, "exampleInputPassword1")
    _WD_ElementAction($sWDSession, $sPasswordInput, "VALUE", $sPassword)

    Local $sCheckBox = _WD_GetElementByID($sWDSession, "exampleCheck1")
    _WD_ElementAction($sWDSession, $sCheckBox, "click")
EndFunc

Func _Setup_IEDriver()
    _WD_Option('Driver', @ScriptDir & '\include\' & (@Compiled ? '' : 'Exe_externe\') & 'IEDriverServer.exe')
    _WD_Option('DriverParams', '--log trace ')
    _WD_Option('Port', 5555)
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": { "se:ieOptions" : {"ie.edgepath":"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe", "ie.edgechromium":true, "ignoreProtectedModeSettings":true, "args" : ["start-maximized", "disable-infobars"]}}}}'
    _WD_Startup()
EndFunc   ;==>_Setup_IEDriver

OS : Windows 10

Autoit version : 3.3.16.0

Webdriver UDF : 0.8.1

WinHttp : 1.6.4.2

Driver : IE Driver Server version 4.0.0.0 (32 Bit)

Link to post
Share on other sites
  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 05/02/2022
Posted (edited)

I got a _WD_ElementAction 'clear' that is not working on Edge with IEDriver but is working on Mozilla with geckodriver (exact same input and code) :
 

Local $sEmailInput = _WD_GetElementByID($sWDSession, "exampleInputEmail1")
_WD_ElementAction($sWDSession, $sEmailInput, "VALUE", $sEmail)
_WD_ElementAction($sWDSession, $sEmailInput, "clear")

Output : error : 10 ($_WD_ERROR_Exception)

So i'm looking to send keyboard command into the input in order to send "CTRL+a" then "delete" and i saw some example in this forum, so i tried this to first send "enter" keyboard command (here is the list😞

Local $sEmailInput = _WD_GetElementByID($sWDSession, "exampleInputEmail1")
_WD_ElementAction($sWDSession, $sEmailInput, "VALUE", $sEmail)
_WD_ElementAction($sWDSession, $sEmailInput, "value", "\uE007")

The result is "\uE007" written into the input, what i'm missing ?

Edited by Keras
Link to post
Share on other sites
Posted (edited)

I went for something proper than sending keyboard command. It works both with IEDriver and Geckodriver :

Local $sElement = _WD_GetElementByName($oSelf.sWDSession, $sQuery)
Local $sJsonElement = '{"element-6066-11e4-a52e-4f735466cecf":"' & $sElement & '"}'
_WD_ExecuteScript($oSelf.sWDSession, "arguments[0].value = '' ;", $sJsonElement)

 

Edited by Keras
Link to post
Share on other sites

How did you declare 

$oSelf

 

?

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 for other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2022-03-07

Link to post
Share on other sites
2 hours ago, Keras said:
Local $sElement = _WD_GetElementByName($oSelf.sWDSession, $sQuery)
Local $sJsonElement = '{"element-6066-11e4-a52e-4f735466cecf":"' & $sElement & '"}'
_WD_ExecuteScript($oSelf.sWDSession, "arguments[0].value = '' ;", $sJsonElement)

 

I tested this code with chromedriver to set a value of an element and this is superfast compared to _WD_ElementAction, $sSession, $sElement, "value", $sValue).
However, it doesn't work if $sValue contains a @CR or @LF character.  Any suggestion to allow these characters?

Link to post
Share on other sites
Posted (edited)
1 hour ago, Danp2 said:

Can you test this scenario with _WD_SetElementValue using an $iStyle of $_WD_OPTION_Advanced?

My $sValue looks like this:
 

<table style="border-collapse: collapse; border-style: solid; border-color: black; text-align: center; font-size: 110%" cellspacing="0" cellpadding="0" width=700 border="1">
<tbody><tr bgcolor="FFFFCC" height=30>
<td style="vertical-align: middle" width=90><b>일자</b></td>
<td style="vertical-align: middle" width=50><b>요일</b></td>
<td style="vertical-align: middle" width=70><b>코스</b></td>
<td style="vertical-align: middle" width=50><b>티타임</b></td>
<td style="vertical-align: middle" width=80><b>예약자</b></td>
<td style="vertical-align: middle" width=300><b>참가자</b></td></tr>
<tr bgcolor=white height=30>
<td style="vertical-align: middle" rowspan=1><a href=????><u>2022.05.10</u></a></td>
<td style="vertical-align: middle" rowspan=1></td>
<td style="vertical-align: middle">IN </td>
<td style="vertical-align: middle">13:00</td>
<td style="vertical-align: middle">박정창  </td>
<td style="vertical-align: middle; padding-left: 7px" align="left">취소</td></tr>
<tr bgcolor=FFFFCC height=30>
<td style="vertical-align: middle" rowspan=1><a href=????><u>2022.05.11</u></a></td>
<td style="vertical-align: middle" rowspan=1></td>
<td style="vertical-align: middle">IN </td>
<td style="vertical-align: middle">13:07</td>
<td style="vertical-align: middle">????</td>
<td style="vertical-align: middle; padding-left: 7px" align="left"><b><span style="color: blue;">????</span></b></td></tr>
<tr bgcolor=white height=30>
<td style="vertical-align: middle" rowspan=1><a href=????><u>2022.05.17</u></a></td>
<td style="vertical-align: middle" rowspan=1></td>
<td style="vertical-align: middle">IN </td>
<td style="vertical-align: middle">13:28</td>
<td style="vertical-align: middle">???  </td>
<td style="vertical-align: middle; padding-left: 7px" align="left">????</td></tr>
<tr bgcolor=FFFFCC height=30>
<td style="vertical-align: middle" rowspan=1><a href=????><u>2022.05.18</u></a></td>
<td style="vertical-align: middle" rowspan=1></td>
<td style="vertical-align: middle">IN </td>
<td style="vertical-align: middle">13:28</td>
<td style="vertical-align: middle">???  </td>
<td style="vertical-align: middle; padding-left: 7px" align="left">????</td></tr>
<tr bgcolor=white height=30>
<td style="vertical-align: middle" rowspan=1><a href=????><u>2022.05.19</u></a></td>
<td style="vertical-align: middle" rowspan=1></td>
<td style="vertical-align: middle">서 OUT</td>
<td style="vertical-align: middle">13:28</td>
<td style="vertical-align: middle">???  </td>
<td style="vertical-align: middle; padding-left: 7px" align="left">????</td></tr>
</tbody></table>

I tested this with @Keras code as follows and it works fine.
 

$sValue = StringReplace($sValue, @CRLF, "")
Local $sJsonElement = '{"element-6066-11e4-a52e-4f735466cecf": "' & $sElement & '"}'
_WD_ExecuteScript($sSession, "arguments[0].value = '" & $sValue & "'; ", $sJsonElement)

_WD_SetElementValue using an $iStyle of $_WD_OPTION_Advanced works with $sValue containing @CRLF, but it can't accomodate double quotation. The following code works fine.
 

$sValue = StringReplace($sValue, '"', "'")
_WD_SetElementValue($sSession, $sElement, $sValue, $_WD_OPTION_Advanced)

I am currently using the following code, borrowed from you, and I will have to stick with this for the time being.
 

_WD_ElementAction($sSession, $sElement, "click")
ClipPut($sValue)
Sleep(100)

$sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE009"},'
$sAction &= '{"type": "pause", "duration": 500},'
$sAction &= '{"type": "keyDown", "value": "v"}, {"type": "keyUp", "value": "v"},'
$sAction &= '{"type": "keyUp", "value": "\uE009"}]}]}'
_WD_Action($sSession, "actions", $sAction)

 

Edited by CYCho
Link to post
Share on other sites
  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 07/29/2022
  • Jos locked this topic
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...