Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

1 hour ago, Danp2 said:

This shows that the call to _WD_FindElement successfully returned an array of elements. It appears that your issue is that you are then attempting to pass this array to _WD_ElementAction, which isn't valid. You'll need to pass each element you want to click as a parameter on separate calls to _WD_ElementAction if you need to click more than one element.

But if I use _WD_ElementAction on separate calls can't multi-select. Because the first call highlights the first element to click, but the second call removes highlightment of the first for hightlight the second.

I refer to this multiselect lists, for instance i want to select first and third:

image.png.ccdbc1cc39df3b5f47697389371102c7.png

It is possible to select more than one at once?

Thanks!

Ansal

Share this post


Link to post
Share on other sites
7 minutes ago, ansal said:

But if I use _WD_ElementAction on separate calls can't multi-select. Because the first call highlights the first element to click, but the second call removes highlightment of the first for hightlight the second.

I refer to this multiselect lists, for instance i want to select first and third:

image.png.ccdbc1cc39df3b5f47697389371102c7.png

It is possible to select more than one at once?

Thanks!

Ansal

Forget it, i don't know what I was doing wrong, but, it works!

Thank you very much, Dan.

 

Share this post


Link to post
Share on other sites

Hi Dan,

Can you tell me how i can manipulate a submit form.

I posted a html file : Test_2.html.

In my example i want to click on the submit button but on the console i read : 

__WD_Post: URL=HTTP://127.0.0.1:9515/session/4fe06e9953af3321165d53d8df10a19b/element; $sData={"using":"xpath","value":"//*[@name="submitExample"]"}
__WD_Post: StatusCode=400; ResponseText=missing command parameters
_WD_FindElement: missing command parameters
_WD_FindElement ==> Webdriver Exception: HTTP status = 400

 

Here is my code (to insert on wd_demo.au3 script) :

Func DemoNavigation()

    _WD_Window($sSession, "maximize")

   $url = @ScriptDir & "\" & "TEST_2.html"
   $url = StringReplace($url,"\","/")

   _WD_Navigate($sSession, $url)

   $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@name="submitExample"]')

   debug($sElement)

  ;i don t understand why $sElement is null

  ; so it cannot click on the button

_WD_ElementAction($sSession, $sElement, 'click')


EndFunc

Func Debug($Value)

  ; showing values

    ConsoleWrite($Value & @CRLF)
    InputBox("Debug", $Value, $Value)

EndFunc   ;==>Debug


Thanks for you helps

 

 

TEST_2.html

Share this post


Link to post
Share on other sites
2 minutes ago, danylarson said:

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@name="submitExample"]')

Does it work if you swap the quotes around? Like this --

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@name='submitExample']")

I seem to recall running into this previously...

Share this post


Link to post
Share on other sites

I try to get the coordinates and dimensions of a element

In Python it should work:
 

e = driver.find_element_by_xpath("//someXpath")

location = e.location
size = e.size

print(location)
print(size)

output:

{'y': 202, 'x': 165}
{'width': 77, 'height': 22}

I tried:

$location = _WD_ExecuteScript($sSession, "arguments[0].location;", '{"' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}')

but the result is not the same:

__WD_Post: URL=HTTP://127.0.0.1:4444/session/47f1a912-250a-41c7-ada0-92c042028102/execute/sync; $sData={"script":"arguments[0].location;", "args":[{"element-6066-11e4-a52e-4f735466cecf":"aaaa6465-db27-41ad-8733-5d8e5f8a9951"}]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ExecuteScript: {"value":null}

What is wrong ?

Share this post


Link to post
Share on other sites
1 hour ago, Danp2 said:

@Hamburgo Look at _WD_ElementAction with the 'rect' command.

Thanks for your proposal and I tried:

$location = _WD_ElementAction($sSession, $sElement,'rect')
     MsgBox(4096, "Webdriver | Function: TestPage: " & $sElement, "Location: >" & $location & "<")

The result looks fine, but it is not stored in the variable:

URL=HTTP://127.0.0.1:4444/session/cd0385b0-b936-4d30-bbb2-86e455fad9cc/element/6f35aa51-a313-48c6-ab22-e60e5c70bee3/rect
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":{"x":22.0,"y":2786.0,"width":162.0,"height":22.0}}...
_WD_ElementAction: {"value":{"x":22.0,"y":2786.0,"width":162.0,"height":22.0}}...

. $location Text: ><

Can it be a reason, because the result looks like a JSON-string ?

 

Share this post


Link to post
Share on other sites
1 hour ago, Danp2 said:

I believe it's an object. Try accessing the properties like this --

$location.x

 

I tried a lot and at last the following:

$location = _WD_ElementAction($sSession, $sElement,'rect')

If IsObj($location) Then
    MsgBox($MB_SYSTEMMODAL, "", "The variable is an object")

 Local $sString = "" ; String for displaying purposes

        For $oProperty In $location
            $sString &= $oProperty & " | "
        Next
        
        ConsoleWrite("$sString:  >" & $sString & "<" & @CRLF)

        MsgBox(4096, "Webdriver | Function: TestPage: " & $sElement, "Location: >" & $sString & "<")
Else
    MsgBox($MB_SYSTEMMODAL, "", "The variable is not an object")
EndIf

MsgBox(4096, "Webdriver | Function: TestPage: " & $sElement, "Location: >" & $location.width & "<")

__WD_Get: URL=HTTP://127.0.0.1:4444/session/ca7cca55-bbad-46b5-aa5a-15540481982a/element/68c4ab3e-ec84-4e09-835b-34a9fc95cf49/rect
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":{"x":22.0,"y":1106.0,"width":162.0,"height":22.0}}...
_WD_ElementAction: {"value":{"x":22.0,"y":1106.0,"width":162.0,"height":22.0}}...
$sString:  >x | y | width | height | <
"D:\Scripting\WebDriver\WebDriver-TestPage.au3" (230) : ==> The requested action with this object has failed.:
MsgBox(4096, "Webdriver | Function: TestPage: " & sElement, "Location: >" & $location.width & "<")
MsgBox(4096, "Webdriver | Function: TestPage: " & sElement, "Location: >" & $location^ ERROR
>Exit code: 1    Time: 200.5

By a for-loop I am be able to read the element-names of the object, but do not get access by for example: $location.width

 

Share this post


Link to post
Share on other sites
11 minutes ago, Hamburgo said:

I tried a lot and at last the following:

$location = _WD_ElementAction($sSession, $sElement,'rect')

If IsObj($location) Then
    MsgBox($MB_SYSTEMMODAL, "", "The variable is an object")

 Local $sString = "" ; String for displaying purposes

        For $oProperty In $location
            $sString &= $oProperty & " | "
        Next
        
        ConsoleWrite("$sString:  >" & $sString & "<" & @CRLF)

        MsgBox(4096, "Webdriver | Function: TestPage: " & $sElement, "Location: >" & $sString & "<")
Else
    MsgBox($MB_SYSTEMMODAL, "", "The variable is not an object")
EndIf

MsgBox(4096, "Webdriver | Function: TestPage: " & $sElement, "Location: >" & $location.width & "<")

__WD_Get: URL=HTTP://127.0.0.1:4444/session/ca7cca55-bbad-46b5-aa5a-15540481982a/element/68c4ab3e-ec84-4e09-835b-34a9fc95cf49/rect
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":{"x":22.0,"y":1106.0,"width":162.0,"height":22.0}}...
_WD_ElementAction: {"value":{"x":22.0,"y":1106.0,"width":162.0,"height":22.0}}...
$sString:  >x | y | width | height | <
"D:\Scripting\WebDriver\WebDriver-TestPage.au3" (230) : ==> The requested action with this object has failed.:
MsgBox(4096, "Webdriver | Function: TestPage: " & sElement, "Location: >" & $location.width & "<")
MsgBox(4096, "Webdriver | Function: TestPage: " & sElement, "Location: >" & $location^ ERROR
>Exit code: 1    Time: 200.5

By a for-loop I am be able to read the element-names of the object, but do not get access by for example: $location.width

 

In the W3C-Documentation they are called the result of the rect-command as dictionary and not a object. What is the different ?

 

Share this post


Link to post
Share on other sites
19 minutes ago, Danp2 said:

Right... it's a Dictionary object. You can read about it by searching the forum or using Google, but the correct way to retrieve it's contents is like this --

MsgBox(4096, "Webdriver | Function: TestPage: " & $sElement, "Location: >" & $location.item("width") & "<")

 


Yes, you are right. I found in the forum a example that I understood, in the same second as you send your helpful post.

Many thanks !
 

Share this post


Link to post
Share on other sites

I do not understand the following:

 

$location = _WD_Window($sSession, 'rect')

MsgBox(4096, "Webdriver | Function: TestPage: ", "Location: >" & $location & "<")

_WD_Window give back a simple string instead DictionaryObjekt:

__WD_Get: URL=HTTP://127.0.0.1:4444/session/025055a2-4556-46bc-b005-31acc9e509bb/window/rect
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":{"x":4,"y":40,"width":1296,"height":813}}...
_WD_Window: {"value":{"x":4,"y":40,"width":1296,"height":813}}...

 $location Text: >{"value":{"x":4,"y":40,"width":1296,"height":813}}<

 

Share this post


Link to post
Share on other sites

This may not necessarily be this UDF's issue (maybe the driver's fault), the attribute selector doesn't seem to be working when I use it in _WD_FindElement (with ChromeDriver v74), here is an example of the selector which I used:

[href="/login"]

This is not an issue that I need support with as I went with another way which does not involve using this selector. Just wanted to post about it here :)


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

@Danp2 Unfortunatley I no longer have the line and I couldn't share it even if I had it because it is part of a client's project. But I suggest modifying one of the pages used in the demo script to have a specific attribute and try to select that element only using that attribute in the CSS attribute selector.


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Danp2
      Introduction
      This UDF will allow you to interact with any browser that supports the W3C WebDriver specifications. Supporting multiple browsers via the same code base is now possible with just a few configuration settings.
      Requirements
      JSON UDF https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn
      WinHTTP UDF https://www.autoitscript.com/forum/topic/84133-winhttp-functions/
      WebDriver for desired browser
      Chrome WebDriver https://sites.google.com/a/chromium.org/chromedriver/downloads FireFox WebDriver https://github.com/mozilla/geckodriver/releases Edge WebDriver https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Function List
      Core Functions
      _WD_CreateSession($sDesiredCapabilities='{}') _WD_DeleteSession($sSession) _WD_Status() _WD_Timeouts($sSession, $sTimeouts = '') _WD_Navigate($sSession, $sURL) _WD_Action($sSession, $sCommand) _WD_Window($sSession, $sCommand, $sOption = '') _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement = "", $lMultiple = False) _WD_ElementAction($sSession, $sElement, $sCommand, $sOption='') _WD_ExecuteScript($sSession, $sScript, $sArguments="[]") _WD_Alert($sSession, $sCommand, $sOption = '') _WD_GetSource($sSession) _WD_Cookies($sSession, $sCommand, $sOption = '') _WD_Option($sOption, $vValue = "") _WD_Startup() _WD_Shutdown() Helper Functions
      _WD_NewTab($sSession, $lSwitch = True, $iTimeout = -1, $sURL = "", $sFeatures = "") _WD_Attach($sSession, $sString, $sMode = 'title') _WD_LinkClickByText($sSession, $sText, $lPartial = True) _WD_WaitElement($sSession, $sElement, $sStrategy, $sSelector[, $iDelay = 0[, $iTimeout = -1]]) _WD_GetMouseElement($sSession) _WD_GetElementFromPoint($sSession, $iX, $iY) _WD_LastHTTPResult() _WD_GetFrameCount() _WD_IsWindowTop() _WD_FrameEnter($sIndexOrID) _WD_FrameLeave() _WD_HighlightElements($sSession, $aElements[, $iMethod = 1]) _WD_jQuerify($sSession[, $sjQueryFile = Default[, $iTimeout = Default]]) _WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "") _WD_ElementSelectAction($sSession, $sSelectElement, $sCommand) _WD_ConsoleVisible($lVisible = False) _WD_LoadWait($sSession[, $iDelay = 0[, $iTimeout = -1[, $sElement = '']]]) _WD_Screenshot($sSession, $sElement = '', $nOutputType = 1) _WD_SelectFiles($sSession, $sStrategy, $sSelector, $sFilename) _WD_GetShadowRoot($sSession, $sStrategy, $sSelector, $sStartElement = "") _WD_IsLatestRelease() _WD_UpdateDriver($sBrowser[, $sInstallDir = Default[, $lFlag64 = Default[, $lForce = Default]]]) _WD_DownloadFile($sURL, $sDest) Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/201106-webdriver-udf-help-support-ii/
       
    • By JohnWIlling
      We are running on a VIrtual Machine via Remote Desktop.  We are having a situation where the loading of the chromedriver.exe is taking longer on the VM than on a physical machine.  It is causing the first call to  WD_Post in _WD_CreateSession to fail.
      To workaround the Issue, I used a simplified version of (_WinAPI_GetTcpTable) UDF to Loop waiting for the driver port to be in the listening state.  At that point, I know that the Post will work:
      Func _WaitForPort($ListenPort) Do Local $tMIB_TCPTABLE = DllStructCreate("dword[6]") Local $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", 0, "BOOL", True) Local $dwSize = $aRet[2] $tMIB_TCPTABLE = DllStructCreate("DWORD[" & $dwSize / 4 & "]") $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", $dwSize, "BOOL", True) If $aRet[0] <> 0 Then Return SetError(1) Local $iNumEntries = DllStructGetData($tMIB_TCPTABLE, 1, 1) Local $aRes[$iNumEntries][6] For $i = 0 To $iNumEntries - 1 Local $Type = DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 0) $aRet = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 2)) ; local port Local $Port = $aRet[0] ConsoleWrite("Checking Row:" & $i & " State:<" & $Type & "> Port:<" & $Port & ">" & @CRLF) ; Type 2 is LISTENING If $Type = 2 And $Port = $ListenPort Then Return 1; EndIF Next Sleep(500); Until 0; Return 0; EndFunc ;==>_WaitForPort  
    • By svenjatzu
      hey hi
      someone please can help me translate my code to be valid for udf webriver?
       
      #RequireAdmin Opt("WinTitleMatchMode",2) ;~ Sleep(10000) ShellExecute("C:\neu\1.lnk") ;~ Sleep(3000) ;~ $PID = ShellExecute("C:\freeneu\tab.exe") ;~ Sleep(30000*5) WinWait("Example Domain - Iron","") Global $sWinTitle = "Example Domain - Iron" Global $avWinList = WinList($sWinTitle) While $avWinList[0][0] < 1 Sleep(250); Wait for new process to create its GUI $avWinList = WinList($sWinTitle) WEnd For $n = 1 To $avWinList[0][0] WinActivate($avWinList[$n][1]) WinMove($avWinList[$n][1], "", 0, 0, 230, 440) Next Opt("WinTitleMatchMode",1) WinWait("Iron") Sleep(5333) WinWait("Iron") Opt("WinTitleMatchMode",2) WinWaitActive("m:") WinWait("m:") WinClose("m:") ;~ Sleep(5000) Sleep(1000) ;~ ProcessClose("tab.exe") ShellExecute(@ScriptDir & "\q2.exe")  
    • By water
      Internet Explorer is nearly dead, newer versions of Firefox can't any longer be automated using Stilgar's FF UDF.
      Hence more and more users (including me) need to look at automating Webbrowsers using WebDriver.
      That's why I have started to create a tutorial in the wiki.
      It should describe all necessary steps from intallation to usage.

      I'm still collecting ideas for the tutorial - that's where you come into play.
      What do you expect to see in such a tutorial?
      Which browsers should be covered (Firefox, Chrome and Edge are settled)? Any questions for the FAQ? Which (high level) coding examples do you expect (like "How to attach to a running browser instance") ... Like to see your comments
       
      ToDo-List:
      Add "Tools" section and add ChroPath plugin. Done. FAQ: "How to attach to a running browser instance". Done. Explain the difference between iuiautomation, iaccessible, autoit, webdriver. Done. The AutoIt FAQ 40 has been extended. Detailed description of each function. Done Example for "how to deal with downloading". Use function _WD_DownloadFile. Example for "how to deal with popups (alerts, print or save dialog). Use function_WD_AlertRespond to respond to a user prompt. Example for "how to deal with multiple tabs". Use functions _WD_NewTab (create a new tab), _WD_Window (close or switch to a tab) and _WD_Attach (attach to existing tab).
    • By water
      The WebDriver UDF provides a toolbox full of functions to facilitate automating Web browsers.
      Still scripts can become quite complex.
      In this thread users can post "real life" examples to show how specific tasks can be implemented.
      Note
      When posting an example please describe the purpose of the script and the WebDriver functionality used!
       
×
×
  • Create New...