Jump to content

WebDriver UDF (W3C compliant version) - 2022/10/03


Recommended Posts

  • Replies 1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Latest update just released. See below for change log.  

Posted Images

Hello Dan,

we were using FFau3 together with MozRepl and want to change to your UDF. We did not find a function to read content from a webpage element. Is it _WD_Action or _WD_ElementAction? How does it work?

Another question: does _WD_LoadWait return the same as _WD_FindElement?  If not, that would save code.

Have a nice weekend

Hans

Link to post
Share on other sites

Hi Hans,

You would use _WD_ElementAction to interact with an element. To retrieve its value, use 'text' as the value for  the $sCommand parameter.

3 hours ago, HJL said:

Another question: does _WD_LoadWait return the same as _WD_FindElement?  If not, that would save code.

This has been previously suggested for _WD_WaitElement. Is that what you mean? If not, please elaborate.

Link to post
Share on other sites

Here is my radio buttons example:

My example radio buttons

Here is my simple code:

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

Local $sDesiredCapabilities, $sSession

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

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":[' & """start-maximized""," & " ""disable-infobars""" & "" & '] }}}}'
 EndFunc   ;==>SetupChrome

SetupChrome()
_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_custom_radio")

$radio_4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@class='checkmark']")
_WD_ElementAction($sSession, $radio_4, 'click')

_WD_Shutdown()

Can you help me to choose the radio button "Four". I have tried several times. I am new to this UDF, html and css. Thank you  <3

Screenshot (12).png

Link to post
Share on other sites

That site uses iframes, so you'll need to switch to the correct frame before you can locate the element with WD_FindElement. This can be done with _WD_Window or the helper function _WD_FrameEnter.

Check out the DemoFrames function in wd_demo.au3 for an example of using these functions.

Link to post
Share on other sites
On 10/11/2018 at 10:38 AM, Danp2 said:

That site uses iframes, so you'll need to switch to the correct frame before you can locate the element with WD_FindElement. This can be done with _WD_Window or the helper function _WD_FrameEnter.

Check out the DemoFrames function in wd_demo.au3 for an example of using these functions.

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

Local Enum $eFireFox = 0, _
            $eChrome

Local $aDemoSuite[][2] = [["DemoTimeouts", False], ["DemoNavigation", False], ["DemoElements", False], ["DemoScript", False], ["DemoCookies", False], ["DemoAlerts", False],["DemoFrames", False], ["DemoActions", True]]

Local Const $_TestType = $eFireFox
Local $sDesiredCapabilities
Local $iIndex
Local $sSession

$_WD_DEBUG = $_WD_DEBUG_Info
SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_custom_radio")
ConsoleWrite("Frames=" & _WD_GetFrameCount($sSession) & @CRLF)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='iframeResult']")
_WD_FrameEnter($sSession, $sElement)
$text = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input")
_ArrayDisplay($text)
_WD_FrameLeave($sSession)
Sleep(30000)

_WD_DeleteSession($sSession)
_WD_Shutdown()

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

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

I have tried that example but i still don't know how to click that radio or reach to its ID . I am noob, can you tell clearlier?

Link to post
Share on other sites

That site is odd because it's using a custom radio button, but here's two ways to select the radio buttons --

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

Local $sDesiredCapabilities
Local $iIndex
Local $sSession

$_WD_DEBUG = $_WD_DEBUG_Info

SetupChrome()

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_custom_radio")
ConsoleWrite("Frames=" & _WD_GetFrameCount($sSession) & @CRLF)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='iframeResult']")
_WD_FrameEnter($sSession, $sElement)

; Method 1
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//label[3]/input")
_WD_ElementAction($sSession, $sElement, 'click')

Sleep(3000)

; Method 2
$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input", "", True)
;_ArrayDisplay($aElements)
_WD_ElementAction($sSession, $aElements[0], 'click')

Sleep(3000)

_WD_FrameLeave($sSession)
_WD_DeleteSession($sSession)
_WD_Shutdown()

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

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}'
EndFunc   ;==>SetupChrome

 

Link to post
Share on other sites
On 9.11.2018 at 2:09 PM, Danp2 said:

Hi Hans,

You would use _WD_ElementAction to interact with an element. To retrieve its value, use 'text' as the value for  the $sCommand parameter.

This has been previously suggested for _WD_WaitElement. Is that what you mean? If not, please elaborate.

_WD_WaitElement is what I was looking for - perfect. Thanks for your help and for this UDF....

Link to post
Share on other sites
#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities
Local $iIndex
Local $sSession

$_WD_DEBUG = $_WD_DEBUG_Info

SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.youtube.com/")
Sleep(500)
_WD_Action($sSession, "actions", 'PageDown')
;ControlSend($handles, "", $controlID, '{PGDN}')
Sleep(20000)
_WD_DeleteSession($sSession)
_WD_Shutdown()

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

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

i try this with Youtube, key wasn't sent. Should i use ControlSend? Can i get controlID and handle of my session with this UDF?

Link to post
Share on other sites

Hey Danp2, thanks for creating this UDF :)

Didnt code some time, so maybe Iam just confused, but I cant get it to run^^...

  • I downloaded the UDFs JSON, WinHttp and this one. 
  • I unpacked the chromedriver in the same folder with wd_demo.
  • I started the demo with SciTE and changed: Local Const $_TestType = $eChrome
  • I start the demo (1 Chrome window is already open), and nothing happens with Chrome. All I can see, is that the driver is opening.

Iam using the newest Chrome version, every UDF and the driver are fresh downloaded, my AutoIt version is: 3.3.14.2

The demo is closing after a few seconds, my console says:

_WDStartup: OS: WIN_10 WIN32_NT 17134 
_WDStartup: AutoIt: 3.3.14.2
_WDStartup: WD.au3: 0.1.0.15
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --log-path="C:\Users\Acanis\Downloads\Chromedriver\chrome.log"
_WDStartup: Port:   9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}
__WD_Post: StatusCode=400; ResponseText={"value":{"error":"invalid argument","message":"unrecognized capability: chromeOptions","stacktrace":"Backtrace:\n\tOrdinal0 [0x00CD4CB0+1526960]\n\tOrdinal0 [0x00C40C1D+920605]\n\tOrdinal0 [0x00BE5177+545143]\n\tOrdinal0 [0x00B65B94+23444]\n\tOrdinal0 [0x00B8CA63+182883]\n\tOrdinal0 [0x00B8D0B7+184503]\n\tOrdinal0 [0x00B8CEAD+183981]\n\tOrdinal0 [0x00B8B95B+178523]\n\tOrdinal0 [0x00B737A0+79776]\n\tOrdinal0 [0x00B74D5C+85340]\n\tOrdinal0 [0x00B74CB0+85168]\n\tGetHandleVerifier [0x00D8E1F1+584865]\n\tOrdinal0 [0x00CE3F63+1589091]\n\tOrdinal0 [0x00CE413D+1589565]\n\tOrdinal0 [0x00CE438A+1590154]\n\tOrdinal0 [0x00CDC937+1558839]\n\tOrdinal0 [0x00CE3DDF+1588703]\n\tOrdinal0 [0x00C5805E+1015902]\n\tOrdinal0 [0x00C643AB+1065899]\n\tOrdinal0 [0x00C644FA+1066234]\n\tOrdinal0 [0x00C63555+1062229]\n\tBaseThreadInitThunk [0x75718484+36]\n\tRtlValidSecurityDescriptor [0x77BE302C+284]\n\tRtlValidSecurityDescriptor [0x77BE2FFA+234]\n"}}
_WD_CreateSession: {"value":{"error":"invalid argument","message":"unrecognized capability: chromeOptions","stacktrace":"Backtrace:\n\tOrdinal0 [0x00CD4CB0+1526960]\n\tOrdinal0 [0x00C40C1D+920605]\n\tOrdinal0 [0x00BE5177+545143]\n\tOrdinal0 [0x00B65B94+23444]\n\tOrdinal0 [0x00B8CA63+182883]\n\tOrdinal0 [0x00B8D0B7+184503]\n\tOrdinal0 [0x00B8CEAD+183981]\n\tOrdinal0 [0x00B8B95B+178523]\n\tOrdinal0 [0x00B737A0+79776]\n\tOrdinal0 [0x00B74D5C+85340]\n\tOrdinal0 [0x00B74CB0+85168]\n\tGetHandleVerifier [0x00D8E1F1+584865]\n\tOrdinal0 [0x00CE3F63+1589091]\n\tOrdinal0 [0x00CE413D+1589565]\n\tOrdinal0 [0x00CE438A+1590154]\n\tOrdinal0 [0x00CDC937+1558839]\n\tOrdinal0 [0x00CE3DDF+1588703]\n\tOrdinal0 [0x00C5805E+1015902]\n\tOrdinal0 [0x00C643AB+1065899]\n\tOrdinal0 [0x00C644FA+1066234]\n\tOrdinal0 [0x00C63555+1062229]\n\tBaseThreadInitThunk [0x75718484+36]\n\tRtlValidSecurityDescriptor [0x77BE302C+284]\n\tRtlValidSecurityDescriptor [0x77BE2FFA+234]\n"}}
_WD_CreateSession ==> Webdriver Exception: unrecognized capability: chromeOptions
Bypass: DemoTimeouts
Bypass: DemoNavigation
Bypass: DemoElements
Bypass: DemoScript
Bypass: DemoCookies
Bypass: DemoAlerts
Bypass: DemoFrames
Running: DemoActions
__WD_Post: URL=HTTP://127.0.0.1:9515/session//url; $sData={"url":"http://google.com"}
__WD_Post: StatusCode=200; ResponseText={"sessionId":"","status":6,"value":{"message":"invalid session id\n  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64)"}}
_WD_Navigate: {"sessionId":"","status":6,"value":{"message":"invalid session id\n  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64)"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session//element; $sData={"using":"xpath","value":"//input[@id="lst-ib"]"}
__WD_Post: StatusCode=400; ResponseText=missing command parameters
_WD_FindElement: missing command parameters
_WD_FindElement ==> Webdriver Exception: HTTP status = 400
$sElement = 
$sAction = {"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"","element-6066-11e4-a52e-4f735466cecf":""}},{"button":2,"type":"pointerDown"},{"button":2,"type":"pointerUp"}]}]}
__WD_Post: URL=HTTP://127.0.0.1:9515/session//actions; $sData={"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"","element-6066-11e4-a52e-4f735466cecf":""}},{"button":2,"type":"pointerDown"},{"button":2,"type":"pointerUp"}]}]}
__WD_Post: StatusCode=200; ResponseText={"sessionId":"","status":6,"value":{"message":"invalid session id\n  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64)"}}
_WD_Action: {"sessionId":"","status":6,"value":{"message":"invalid session id\n  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64)"}}
__WD_Delete: URL=HTTP://127.0.0.1:9515/session//actions
__WD_Delete: StatusCode=200; ResponseText={"sessionId":"","status":6,"value":{"message":"invalid session id\n  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64)"}}
_WD_Action: {"sessionId":"","status":6,"value":{"message":"invalid session id\n  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64)"}}
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/
__WD_Delete: StatusCode=200; ResponseText={"sessionId":"","status":0,"value":null}
_WD_DeleteSession: {"sessionId":"","status":0,"value":null}
+>19:09:44 AutoIt3.exe ended.rc:0
+>19:09:44 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 11.23

The log says:

Quote

[1542737373.914][INFO]: [c19acd60b4cea2210aa6468670f02ae6] COMMAND InitSession {
   "capabilities": {
      "alwaysMatch": {
         "chromeOptions": {
            "w3c": true
         }
      }
   }
}
[1542737373.920][INFO]: [c19acd60b4cea2210aa6468670f02ae6] RESPONSE InitSession ERROR invalid argument: unrecognized capability: chromeOptions
 

Do you know, what Iam doing wrong? :)

 

Thanks

Aca

Link to post
Share on other sites
On 20/11/2018 at 10:10 PM, Danp2 said:

@pempemHY I'd like to better understand the issue. Can you post an example, ideally with a publicly accessible website, where you can't interact with the element unless the browser is full screen?

 

Try this code! Then delete the line "_WD_Window($sSession, 'fullscreen')" and try it again . See the difference.

Edited by pempemHY
My security
Link to post
Share on other sites

@pempemHY I tried running your code, but it seemed to get hung up in this area --

$button_go = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@id='u_0_1w']")
_WD_ElementAction($sSession, $button_go, 'click')

Not sure what this should be doing. Would really help if you could provide a much simpler example to review.

Link to post
Share on other sites
  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2022/10/03
  • Melba23 pinned this topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...