Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

@Danp2  WDVERSION = "0.1.0.10" and the code :  

#include <wd_core.au3>
Local $sDesiredCapabilities='{}'
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "http://www.google.com")
Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='hplogo']")
__WD_HighlightElement($sSession, $sElement)

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

Local $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='gb_P']", "", True)
 __WD_HighlightElements($sSession, $aElements,3)


Sleep(10000)
_WD_DeleteSession($sSession)
_WD_Shutdown()


; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WD_HighlightElement
; Description ...:
; Syntax ........: __WD_HighlightElement($sSession, $sElement[, $iMethod = 1])
; Parameters ....: $sSession            - Session ID from _WDCreateSession
;                  $sElement            - Element ID from _WDFindElement
;                  $iMethod             - [optional] an integer value. Default is 1.
;                  1=style -> Highlight border dotted red
;                  2=style -> Highlight yellow rounded box
;                  3=style -> Highlight yellow rounded box + border  dotted red
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WD_HighlightElement($sSession, $sElement, $iMethod = 1)
    Local Const $aMethod[] = ["border: 2px dotted red", _
            "background: #FFFF66; border-radius: 5px; padding-left: 3px;", _
            "border:2px dotted  red;background: #FFFF66; border-radius: 5px; padding-left: 3px;"]
    If $iMethod < 1 Or $iMethod > 3 Then $iMethod = 1
    Local $sJsonElement = '{"element-6066-11e4-a52e-4f735466cecf":"' & $sElement & '"}'
    Local $sResponse = _WD_ExecuteScript($sSession, "arguments[0].style='" & $aMethod[$iMethod - 1] & "'; return true;", $sJsonElement)
    Local $sJSON = Json_Decode($sResponse)
    Local $sResult = Json_Get($sJSON, "[value]")
    Return ($sResult = "true" ? SetError(0, 0, $sResult) : SetError(1, 0, False))
EndFunc   ;==>__WD_HighlightElement


; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WD_HighlightElements
; Description ...:
; Syntax ........: __WD_HighlightElements($sSession, $aElements[, $iMethod = 1])
; Parameters ....: $sSession            - Session ID from _WDCreateSession
;                  $aElements           - an array of Elements ID from _WDFindElement
;                  $iMethod             - [optional] an integer value. Default is 1.
;                  1=style -> Highlight border dotted red
;                  2=style -> Highlight yellow rounded box
;                  3=style -> Highlight yellow rounded box + border  dotted red
; Return values .: Success      - True
;                  Failure      - False
;                  @Extended Number of Highlighted Elements
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WD_HighlightElements($sSession, $aElements, $iMethod = 1)
    Local $iHighlightedElements = 0
    For $i = 0 To UBound($aElements) - 1
        $iHighlightedElements += (__WD_HighlightElement($sSession, $aElements[$i], $iMethod) = True ? 1 : 0)
    Next
    Return ($iHighlightedElements > 0 ? SetError(0, $iHighlightedElements, True) : SetError(1, 0, False))
EndFunc   ;==>__WD_HighlightElements

the browser is chrome 67.0.3396.99  

the scite console  code :

_WD_Startup ==> Invalid value: Location for Web Driver not set.

__WD_Post: URL=HTTP://127.0.0.1:0/session; $sData={}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_CreateSession: 0
_WD_CreateSession ==> Webdriver Exception: HTTP status = 0
__WD_Post: URL=HTTP://127.0.0.1:0/session//url; $sData={"url":"http://www.google.com"}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_Navigate: 0
_WD_Navigate ==> Webdriver Exception: HTTP status = 0
__WD_Post: URL=HTTP://127.0.0.1:0/session//element; $sData={"using":"xpath","value":"//*[@id='hplogo']"}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_FindElement: 0
_WD_FindElement ==> Send / Recv error: HTTP status = 0
__WD_Post: URL=HTTP://127.0.0.1:0/session//execute/sync; $sData={"script":"arguments[0].style='border: 2px dotted red'; return true;", "args":[{"element-6066-11e4-a52e-4f735466cecf":""}]}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_ExecuteScript: 0
__WD_Post: URL=HTTP://127.0.0.1:0/session//element; $sData={"using":"xpath","value":"//*[@name='btnK']"}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_FindElement: 0
_WD_FindElement ==> Send / Recv error: HTTP status = 0
__WD_Post: URL=HTTP://127.0.0.1:0/session//execute/sync; $sData={"script":"arguments[0].style='background: #FFFF66; border-radius: 5px; padding-left: 3px;'; return true;", "args":[{"element-6066-11e4-a52e-4f735466cecf":""}]}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_ExecuteScript: 0
__WD_Post: URL=HTTP://127.0.0.1:0/session//elements; $sData={"using":"xpath","value":"//*[@class='gb_P']"}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_FindElement: 0
_WD_FindElement ==> Send / Recv error: HTTP status = 0
__WD_Delete: URL=HTTP://127.0.0.1:0/session/
__WD_Delete: StatusCode=0; ResponseText=0
__WD_Delete ==> Webdriver Exception
_WD_DeleteSession: 0
_WD_DeleteSession ==> Webdriver Exception: HTTP status = 0

Share this post


Link to post
Share on other sites

Mouseover using chromedriver?

I need to close some tabs inside a webpage but the x that you click on is not visible until you mouseover the tab you want to close.

Anybody know how I would be able to kick off a mouseover? 

 

I tried just doing a _WD_ElementAction($sSession, $eClose, "click")  while the button was still hidden but it says:  

     _WD_ElementAction: {"value":{"error":"element not visible","message":"(Session infochrome=67.0.3396.99)"

 

I put together a sample script where if we get the Mouseover working it should set the text with a yellow background.

#include "wd_core.au3"
#include "wd_helper.au3"
Local $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars"] }}}}'
Local $sSession
$_WD_DEBUG = True                                                           ;This outputs a TON of debugging stuff to the Console, set to False before compiling.


$sSetup = _SetupChrome()                                                    ;Setup all the requirements for WebDriver to use Chrome how we want
$iStartup = _WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)                        ;Launch Chrome Now
$sNavigate = _WD_Navigate($sSession, "https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_event_mouseover_mouseout")  ;Go to the test site

sleep(1500)

$sFrame = _WD_FrameEnter($sSession, "iframeResult")                         ;I have to use the $sOption = '{"id":"' & $sIndexOrID & '"}' change to get this function to work properly

$eHoverItem = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//p[text()='Move the mouse pointer over this paragraph.']")     ;Find the p element we want to mouseover

_WD_HighlightElement($sSession, $eHoverItem, 1)                             ;Put the dotted line around just to show we have found it

;How to do a Hover/Mouseover?






Func _SetupChrome()
    If _WD_Option('Driver', 'chromedriver.exe') = 0 Then Return SetError(1)
    If _WD_Option('Port', 9515) = 0 Then Return SetError(1)
    If _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') = 0 Then Return SetError(1)
EndFunc   ;==>_SetupChrome

Thanks for any help

Mike

 


hmm... I guess I have to have a signature...

Share this post


Link to post
Share on other sites
17 hours ago, Danp2 said:

Have a look at _WD_Action and the "actions" command. This is where I suspect that the web driver would implement this kind of thing.

Also see here for the details in the W3C specs.

P.S. Let me know how it goes with this. Once you have it working, I can add an example to wd_test. :)

That W3C spec makes no sense to me and everything from google searches just bring up Selenium stuff which doesn't work here.

on the bright side, I did discover that doing _WD_ElementAction($sSession, $eHoverItem, "click") actually performs a mouseover.  I'm sure it's not the best option but in my case the click is ignored by the Tab item but the mouseover pops up the x for me to then click on.


hmm... I guess I have to have a signature...

Share this post


Link to post
Share on other sites

Hello again,

I'm wondering why the _WD_FrameEnter can't seem to handle the value returned from _WD_FindElement()?

I need to go into a frame but the @id changes every time I go into the page so I need to use xpath to find the proper frame, but I can't pass the value returned from _WD_FindElement().

Is there a way to get the @id from what _WD_FindElement() returns?


hmm... I guess I have to have a signature...

Share this post


Link to post
Share on other sites
On 7/17/2018 at 5:52 PM, Danp2 said:

Probably could retrieve the values using _WD_ExecuteScript / Javascript.

@Danp2,

I'm trying to get the size and location using _WD_ExecuteScript and I could get the size of the element but not sure which property to use to get back the location, left and top. Please help if you have any idea regarding this.

Have seen a sample of calling _WD_ExecuteScript on @Danyfirex 's _WD_HighlightElement and reused to call the method

Local $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElementId & '"}'
Local $sResponse = _WD_ExecuteScript($sSession, "return arguments[0].clientHeight", $sJsonElement)
msgbox(0,"Height",$sResponse)
$sResponse = _WD_ExecuteScript($sSession, "return arguments[0].clientWidth", $sJsonElement)
msgbox(0,"Width",$sResponse)
#cs
$sResponse = _WD_ExecuteScript($sSession, "return arguments[0].offsetLeft", $sJsonElement)
msgbox(0,"Left",$sResponse)
$sResponse = _WD_ExecuteScript($sSession, "return arguments[0].offsetTop", $sJsonElement)
msgbox(0,"Top",$sResponse)
#ce

Thank you for all your help.

Reference DOM

Edited by PoojaKrishna

Share this post


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

@BigDaddyO I'll see if I can come up with a working example of _WD_Action / hover. As far as your other question, have you tried testing with a different browser? We've already established that Chromedriver doesn't adhere to the W3C specs in a number of areas.

Thanks for looking into that.  As for Firefox, My company doesn't allow it as they can't secure it how they want.

 

I did finally figure out how to get the IFrame id using _WE_ElementAction()

$eFrame = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@name='iframeResult']")    ;Find the IFrame we need
ConsoleWrite(@CRLF & "Finding Frame result (" & $eFrame & ")" & @CRLF & @CRLF)

$ID = _WD_ElementAction($sSession, $eFrame, 'attribute', 'id')                          ;Get the @id to pass into the _WD_FrameEnter
ConsoleWrite(@CRLF & "Finding The Frame id result (" & $ID & ")" & @CRLF & @CRLF)

$sFrame = _WD_FrameEnter($sSession, $ID)
ConsoleWrite(@CRLF & "Enter Frame result (" & $sFrame & ")" & @CRLF & @CRLF)

 


hmm... I guess I have to have a signature...

Share this post


Link to post
Share on other sites

Hello @BigDaddyO You can trigger the mouseover event using javascript.

 

Local $sJsonElement = '{"element-6066-11e4-a52e-4f735466cecf":"' & $eHoverItem & '"}'
Local $sResponse = _WD_ExecuteScript($sSession, "$('p').mouseover(); return true;", $sJsonElement)

Saludos

 

 

Saludos

Share this post


Link to post
Share on other sites
11 hours ago, Danp2 said:

@PoojaKrishna There are lots of examples on the web for doing this. Here's one such example, which you should be able to translate into a series of _WD_ExecuteScript calls.

Thank you so much @Danp2, it worked!!!

Reference

Local $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElementId & '"}'
_WD_ExecuteScript($sSession, "return arguments[0].getBoundingClientRect().left", $sJsonElement)
_WD_ExecuteScript($sSession, "return arguments[0].getBoundingClientRect().top", $sJsonElement)
_WD_ExecuteScript($sSession, "return arguments[0].getBoundingClientRect().right", $sJsonElement)
_WD_ExecuteScript($sSession, "return arguments[0].getBoundingClientRect().bottom", $sJsonElement)
_WD_ExecuteScript($sSession, "return arguments[0].getBoundingClientRect().x", $sJsonElement)
_WD_ExecuteScript($sSession, "return arguments[0].getBoundingClientRect().y", $sJsonElement)
_WD_ExecuteScript($sSession, "return arguments[0].getBoundingClientRect().width", $sJsonElement)
_WD_ExecuteScript($sSession, "return arguments[0].getBoundingClientRect().height", $sJsonElement)

 

Share this post


Link to post
Share on other sites

Back again with a question. :sweating:

I am trying to context click on an element. Can I use _WD_Action to context click an element ? I know _WD_ExecuteScript can be used but can we create object of class action to use in the script and pass as parameter? If any one has a sample script, then please post. It would be a great help. 

_WD_Action($sSession, 'actions', 'contextClick')

 

Share this post


Link to post
Share on other sites

@PoojaKrishna Here's an example I was able to come up with after some Googling --

_WD_Navigate($sSession, "http://google.com")
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib']")

    $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"}]}]}'

    _WD_Action($sSession, "actions", $sAction)

 

Share this post


Link to post
Share on other sites
8 hours ago, Danp2 said:

@PoojaKrishna Here's an example I was able to come up with after some Googling --

_WD_Navigate($sSession, "http://google.com")
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib']")

    $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"}]}]}'

    _WD_Action($sSession, "actions", $sAction)

 

Thank you @Danp2 but it returns an error on my testings.

{"value":{"error":"unknown command","message":"(Session infochrome=67.0.3396.99)","stacktrace":"Backtrace:\n\tOrdinal0 [0x013DDF70+778096]\n\tOrdinal0 [0x0138B42D+439341]\n\tOrdinal0 [0x01367E1D+294429]\n\tOrdinal0 [0x0134D9D3+186835]\n\tOrdinal0 [0x01348323+164643]\n\tOrdinal0 [0x01331B45+72517]\n\tOrdinal0 [0x01332F2A+77610]\n\tOrdinal0 [0x01332ECC+77516]\n\tGetHandleVerifier [0x01479936+3478]\n\tOrdinal0 [0x013E88C3+821443]\n\tOrdinal0 [0x01397066+487526]\n\tOrdinal0 [0x01397393+488339]\n\tOrdinal0 [0x013974A3+488611]\n\tOrdinal0 [0x013EAA67+830055]\n\tOrdinal0 [0x01396DAF+486831]\n\tOrdinal0 [0x013A13FE+529406]\n\tOrdinal0 [0x013AC57B+574843]\n\tOrdinal0 [0x013AC6CD+575181]\n\tOrdinal0 [0x013AB92B+571691]\n\tBaseThreadInitThunk [0x76C88484+36]\n\tRtlValidSecurityDescriptor [0x774D2FEA+282]\n\tRtlValidSecurityDescriptor [0x774D2FBA+234]\n"}}

The action statement was like: 

{"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"978ac653-1ffa-46a1-bf0b-c3551ffd74a6","element-6066-11e4-a52e-4f735466cecf":"978ac653-1ffa-46a1-bf0b-c3551ffd74a6"}},{"button":2,"type":"pointerDown"},{"button":2,"type":"pointerUp"}]}]}
 

 

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 Jgladden
      Dan - thanks for all that you do - this stuff is great. 
      Hoping you can assist with an issue we are having now that we have moved to Windows 10/Server 2016. The Chrome interactions were working flawlessly until moving over. Now my code fails when attempting to create the session. As you can see, our Chrome install is not in a standard location but I have validated the path to the binary. I have attached some detail below including system info, console output and the chrome log detail. I have tried several recommendations that have seen in various forums but none have made a difference
      Any assistance you can give would be greatly appreciated. 
      Thanks in advance, 
      chrome_Details.txt
    • 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/
      HtmlTable2Array UDF (optional) https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/
      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/ Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      See the wiki for details on the UDF --
      https://www.autoitscript.com/wiki/WebDriver
      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 Langmeister
      I am once again asking for your experienced assistance. If I open a website that uses notifications I am asked to allow or block them for that website after a few seconds. This notification pops up every time the page gets navigated to, even tho you have clicked on allow for several times. I am explicitly not searching for smth to get rid of "Chrome is being controlled by automated test sw". Instead I am searching for a line of script to disable all notifications by default: like here chrome://settings/content/notifications. 
      This is code should give you an example of what notifications I am talking about:
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://webradio.planetradio.de/") _WD_LoadWait($sSession)  
    • By Langmeister
      Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.
      I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan") _WD_LoadWait($sSession) Sleep(3000) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a") _WD_ElementAction($sSession, $sElement, 'text') ClipGet() Run("notepad.exe") Sleep(500) Send("^v") Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.
      __WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}... _WD_ElementAction: {"value":"Shark Awareness Day"}... Thanks in advance! 
       
    • By Langmeister
      Hi, I need help performing actions in Salesforce using IE. I used to complete tasks via MouseMove/MouseClick etc. on the Chrome application of SF, but unfortunately this only works for me and not my colleagues due to different positions of things etc. Being unable to get Webdriver UDF or Chromedriver running to interact with the code directly, I chose to look into the IE UDF. ATM I'm trying to tick a specific checkbox in SF which simply allows me to "select all checkboxes" at the same time. Applying the following code on a random website with checkboxes works just fine for me: (in this case selecting cheese checkbox)
      #include <IE.au3> Local $oIE = _IECreate("http://www.echoecho.com/htmlforms09.htm") Local $oSubmit = _IEGetObjByName($oIE, "option3") _IEAction($oSubmit, "click") _IELoadWait($oIE) But applying it to the Salesforce website it does exactly nothing and responds with these warnings/errors:
      The script is exactly the same, except for website and the input name tag of the desired checkbox being different.
      #include <IE.au3> Local $oIE = _IECreate("Corporate Salesforce URL") Local $oSubmit = _IEGetObjByName($oIE, "myPage:myForm:oliListBlock:oliListTable:j_id36") _IEAction($oSubmit, "click") _IELoadWait($oIE) As its working with random websites my guess is that there has to be something done to get it work with SF.
      Hope the more experienced SF+AutoIt pros can help me out here. Thanks in advance!
×
×
  • Create New...