Jump to content

WebDriver UDF (W3C compliant version) - 2024/09/21


Danp2
 Share

Recommended Posts

@rkskaras More details are needs to be able to assist you, such as the version number for both MSEdge and the MSEdgeDriver. Have you tried running wd_demo with Edge? I just did this and it worked as expected.

If you need further assistance, post a short script that will show up what you are attempting to do. Be sure to also post the results from the Scite output panel so that we can check the output from the Webdriver UDF calls.

Link to comment
Share on other sites

na verdade não é um erro, você está recebendo um array com as informações...

precisa criar uma variável local que procure dentro de cada ítem...

e então extrair o valor que deseja..

 

 $tabelaElemento = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='xxxxx']")
      $elemento = _WD_ElementAction($sSession,  $tabelaElemento, 'Attribute', 'value')

 

deve fazer mais ou menos isso para extrair o valor interno do dentro do $i do for...

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

@Danp2 Sorry for late response i had a lot of work to do.

I need to test our application through Edge browser but the problem is as i told you earlier is that somehow script can not get sessionId.

I am using your wd_demo.au3 with Edge enabled.

 

And in the output i recieve this

 

_WDStartup: OS: WIN_10 WIN32_NT 10586 
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.1.0.20
_WDStartup: Driver: MicrosoftWebDriver.exe
_WDStartup: Params: --host=127.0.0.1
_WDStartup: Port:   17556
__WD_Post: URL=HTTP://127.0.0.1:17556/session; $sData={}
__WD_Post: StatusCode=200; ResponseText={"sessionId":"9115EBCA-F8F8-47E2-A27B-14FDC6E4786D","status":0,"value":{"browserName":"MicrosoftEdge","browserVersion":"25.10586.672.0","platformName":"windows","platformVersion":"10","takesElementScreenshot":true,"takesScreenshot":true,"acceptSslCerts":true,"pageLoadStrategy":"normal"}}
_WD_CreateSession: {"sessionId":"9115EBCA-F8F8-47E2-A27B-14FDC6E4786D","status":0,"value":{"browserName":"MicrosoftEdge","browserVersion":"25.10586.672.0","platformName":"windows","platformVersion":"10","takesElementScreenshot":true,"takesScreenshot":true,"acceptSslCerts":true,"pageLoadStrategy":"normal"}}
_WD_CreateSession ==> Webdriver Exception
__WD_Post: URL=HTTP://127.0.0.1:17556/session//url; $sData={"url":"https://google.com"}
__WD_Post: StatusCode=404; ResponseText=Unknown command received
_WD_Navigate: Unknown command received

Notice in the line

__WD_Post: URL=HTTP://127.0.0.1:17556/session//url; $sData={"url":"https://google.com"}

Between /session/ and /url there should be sessionId. It should be like this 

__WD_Post: URL=HTTP://127.0.0.1:17556/session/9115EBCA-F8F8-47E2-A27B-14FDC6E4786D/url; $sData={"url":"https://google.com"}

I am using your latest scripts from your github. I tried to fix it manually but i dont have sufficent knowledge. 

Also i am using part of your wd_demo.au3

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

Local $sDesiredCapabilities, $sSessionn
SetupEdge()

_WD_Startup()
$sSessionn = _WD_CreateSession($sDesiredCapabilities)
 _WD_Navigate($sSessionn, "https://google.com")
;~ _ChromeSetInputValueById($sSession, 'email', 'test')
;~ _ChromeSetInputValueById($sSession, 'pass', 'test')



Func SetupEdge()
_WD_Option('Driver', 'MicrosoftWebDriver.exe')
_WD_Option('Port', 17556)
_WD_Option('DriverParams', '--host=127.0.0.1')

$sDesiredCapabilities = '{}'
EndFunc

;// CANT DETERMINE SESSION ID

 

Thank you in advance.

Link to comment
Share on other sites

@rkskaras I've just testing using both versions of Edge (regular and Canary release) and it functioned as I expected. I notice that your desiredCapabilities string is empty. You may want to rethink that (look at the current setup in wd_demo script).

Also, it appears that you are running a very old version of Edge. Suggest that you upgrade to a more current release as that should resolve your issue.

Link to comment
Share on other sites

@Danp2 I checked your wd_demo script and desiredCapabilities is also empty.

Func SetupEdge()
_WD_Option('Driver', 'MicrosoftWebDriver.exe')
_WD_Option('Port', 17556)
_WD_Option('DriverParams', '--verbose')

$sDesiredCapabilities = '{"capabilities":{}}'
EndFunc

 

I also had to replace in _WD_Option --verbose with --host=127.0.0.1 otherwise it wont work.

Yea unfortunately  I can't update Edge version because I am working on company VDIs.

I also tested Google Chrome and Firefox and they work very well.

Is there any other option to try ?

 

 

Link to comment
Share on other sites

@rkskaras Sorry about that. I was looking at my local copy, which contains the following --

Func SetupEdge()
; Edge (Canary)
_WD_Option('Driver', 'MSEdgeDriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\msedge.log"')

; Edge (standard)
_WD_Option('Driver', 'MicrosoftWebDriver.exe')
_WD_Option('Port', 17556)
_WD_Option('DriverParams', '--host=127.0.0.1')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c":true, "binary":"' & StringReplace (@UserProfileDir, "\", "/") & '/AppData/Local/Microsoft/Edge SxS/Application/msedge.exe"}}}}'
EndFunc

 

11 minutes ago, rkskaras said:

Yea unfortunately  I can't update Edge version because I am working on company VDIs.

That's too bad. The sessionId  should be returned inside the "value" key. Unfortunately, this older version of Edge doesn't respect the W3C standards. Suggest that you clone _WD_CreateSession to _WD_CreateSessionEdge and change it to handle to wrong value being returned by the driver.

You could try changing this line --

$sSession = Json_Get($sJSON, "[value][sessionId]")

to --

$sSession = Json_Get($sJSON, "[sessionId]")

Please remember that this UDF is designed to support the latest W3C standard. You may run into other issues while using an outdated browser, so be prepared to troubleshoot other anomalies as they arise. 😉

Good luck!

Dan

 

Link to comment
Share on other sites

Hi all,

I'm trying to get my Chrome window maximized using the WebDriver UDF, using the following script (hence the line: "_WD_Window($sSession, "maximize", "")"):

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

Local $sDesiredCapabilities
Local $sSession

SetupChrome()

_WD_Startup()

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

$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.google.com")
_WD_Window($sSession, "maximize", "")

;_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": {"goog:chromeOptions": {"w3c": true }}}}'
EndFunc

The logging result is:

_WDStartup: OS:    WIN_10 WIN32_NT 18362 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.20
_WDStartup: Driver:    chromedriver.exe
_WDStartup: Params:    --log-path="C:\AutoIT\Examples\chrome.log"
_WDStartup: Port:    9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}
__WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"76.0.3809.132","chrome":{"chromedriverVersion":"76.0.3809.126 (d80a294506b4c9d18015e755cee48f953ddc3f2f-refs/branch-heads/3809@{#1024})","userDataDir":"C:\\[somethingnotforposting]\\AppData\\Local\\Temp\\scoped_dir9308_677972690"},"goog:chromeOptions":{"debuggerAddress":"localhost:57206"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows nt","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"},"sessionId":"ba3347b1ea5edfee1a886b7fc82d2c4d"}}
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"76.0.3809.132","chrome":{"chromedriverVersion":"76.0.3809.126 (d80a294506b4c9d18015e755cee48f953ddc3f2f-refs/branch-heads/3809@{#1024})","userDataDir":"C:\\[somethingnotforposting]\\AppData\\Local\\Temp\\scoped_dir9308_677972690"},"goog:chromeOptions":{"debuggerAddress":"localhost:57206"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows nt","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"},"sessionId":"ba3347b1ea5edfee1a886b7fc82d2c4d"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/ba3347b1ea5edfee1a886b7fc82d2c4d/url; $sData={"url":"https://www.google.com"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/ba3347b1ea5edfee1a886b7fc82d2c4d/window/maximize; $sData=
__WD_Post: StatusCode=400; ResponseText={"value":{"error":"invalid argument","message":"invalid argument: missing command parameters","stacktrace":"Backtrace:\n\tOrdinal0 [0x00B67C53+1473619]\n\tOrdinal0 [0x00AEAD71+961905]\n\tOrdinal0 [0x00A742B3+475827]\n\tOrdinal0 [0x00A25ED4+155348]\n\tOrdinal0 [0x00A25B16+154390]\n\tOrdinal0 [0x00A021FE+8702]\n\tOrdinal0 [0x00A02616+9750]\n\tOrdinal0 [0x00A02C00+11264]\n\tOrdinal0 [0x00B04B37+1067831]\n\tGetHandleVerifier [0x00C06845+506677]\n\tGetHandleVerifier [0x00C065E0+506064]\n\tGetHandleVerifier [0x00C0D188+533624]\n\tGetHandleVerifier [0x00C0701A+508682]\n\tOrdinal0 [0x00AFC226+1032742]\n\tOrdinal0 [0x00AFC09F+1032351]\n\tOrdinal0 [0x00A0203A+8250]\n\tOrdinal0 [0x00A01D62+7522]\n\tGetHandleVerifier [0x00F4915C+3925068]\n\tBaseThreadInitThunk [0x77936359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77A77A94+228]\n\tRtlGetAppContainerNamedObjectPath [0x77A77A64+180]\n"}}
_WD_Window: {"value":{"error":"invalid argument","message":"invalid argument: missing command parameters","stack...
_WD_Window ==> Webdriver Exception: HTTP status = 400

Please notice the error at the end, for a missing parameter "Options" for the maximizing of the window.

Which option should I use to make sure to maximize the window? Leaving the empty Options parameter out of the command, won't make a difference.

Thanks in advance.

Link to comment
Share on other sites

  • 2 weeks later...
13 minutes ago, Triguit0 said:

#shadow-root

No idea what this is. Please provide more detail, such as --

  • Website URL
  • Short script showing what you've tried
  • Results from Scite output window
  • etc

Edit: I did some digging and now have a slightly better understanding of shadow roots. Unfortunately, it doesn't appear that these custom DOMs can be accessed with the standard webdriver functions.

Edited by Danp2
Link to comment
Share on other sites

Hi Danp2,

Thanks for replying so fast.

Im actually trying to access a Div inside a shadow-root.

image.png.afda38797fc1aa45f5bbd2408d25fda0.png

Scite output window:

__WD_Post: URL=HTTP://127.0.0.1:9515/session/a7e30f8f7b44b762b8cae151b3f5af15/element; $sData={"using":"tag name","value":"downloads-manager"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"e76ba505-f16e-4f65-b04c-c82b08f3f6b9"}}
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"e76ba505-f16e-4f65-b04c-c82b08f3f6b9"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/a7e30f8f7b44b762b8cae151b3f5af15/element; $sData={"using":"xpath","value":"//downloads-manager/div[@id='mainContainer']"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//downloads-manager/div[@id='mainContainer']\"}\n  (Session info: chrome=77.0.3865.90)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0100EB13+1501971]\n\tOrdinal0 [0x00F8F6D1+980689]\n\tOrdinal0 [0x00F1765F+489055]\n\tOrdinal0 [0x00EB7152+94546]\n\tOrdinal0 [0x00ED0E00+200192]\n\tOrdinal0 [0x00EC7A80+162432]\n\tOrdinal0 [0x00ECF93E+194878]\n\tOrdinal0 [0x00EC78EB+162027]\n\tOrdinal0 [0x00EB0AC7+68295]\n\tOrdinal0 [0x00EB1B40+72512]\n\tOrdinal0 [0x00EB1AD9+72409]\n\tOrdinal0 [0x00FA8F37+1085239]\n\tGetHandleVerifier [0x010AD7ED+503293]\n\tGetHandleVerifier [0x010AD580+502672]\n\tGetHandleVerifier [0x010B46AC+531644]\n\tGetHandleVerifier [0x010ADFFA+505354]\n\tOrdinal0 [0x00FA0606+1050118]\n\tOrdinal0 [0x00FA047F+1049727]\n\tOrdinal0 [0x00FAAF9B+1093531]\n\tOrdinal0 [0x00FAB103+1093891]\n\tOrdinal0 [0x00FAA095+1089685]\n\tBaseThreadInitThunk [0x73C68484+36]\n\tRtlValidSecurityDescriptor [0x7705305A+282]\n\tRtlValidSecurityDescriptor [0x7705302A+234]\n"}}
_WD_FindElement: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//downloads-manager/div[@id='mainContainer']\"}\n  (Session info: chrome=77.0.3865.90)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0100EB13+1501971]\n\tOrdinal0 [0x00F8F6D1+980689]\n\tOrdinal0 [0x00F1765F+489055]\n\tOrdinal0 [0x00EB7152+94546]\n\tOrdinal0 [0x00ED0E00+200192]\n\tOrdinal0 [0x00EC7A80+162432]\n\tOrdinal0 [0x00ECF93E+194878]\n\tOrdinal0 [0x00EC78EB+162027]\n\tOrdinal0 [0x00EB0AC7+68295]\n\tOrdinal0 [0x00EB1B40+72512]\n\tOrdinal0 [0x00EB1AD9+72409]\n\tOrdinal0 [0x00FA8F37+1085239]\n\tGetHandleVerifier [0x010AD7ED+503293]\n\tGetHandleVerifier [0x010AD580+502672]\n\tGetHandleVerifier [0x010B46AC+531644]\n\tGetHandleVerifier [0x010ADFFA+505354]\n\tOrdinal0 [0x00FA0606+1050118]\n\tOrdinal0 [0x00FA047F+1049727]\n\tOrdinal0 [0x00FAAF9B+1093531]\n\tOrdinal0 [0x00FAB103+1093891]\n\tOrdinal0 [0x00FAA095+1089685]\n\tBaseThreadInitThunk [0x73C68484+36]\n\tRtlValidSecurityDescriptor [0x7705305A+282]\n\tRtlValidSecurityDescriptor [0x7705302A+234]\n"}}
_WD_FindElement ==> No match: HTTP status = 404

Link to comment
Share on other sites

3 hours ago, Triguit0 said:

Im actually trying to access a Div inside a shadow-root.

It looks like there is some effort to add Shadow DOM handling to the W3C specs. See here for more details.

In the mean time, you can access these objects using _WD_ExecuteScript along with javascript. For example, here's a quick and dirty way to retrieve the element you showed above --

$sScript = 'return document.querySelector("downloads-manager").shadowRoot.querySelector("#mainContainer");'
_WD_ExecuteScript($sSession, $sScript, "")

The output will be a raw JSON string from which you will need to extract the last node (see this post from earlier today for details on how to do that). Then you'll need to test and see if this value can successfully be used with other functions from this UDF.

Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2024/09/21
  • 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
 Share

×
×
  • Create New...