Jump to content

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


Danp2
 Share

Recommended Posts

It´s really simple.

The interaction with the frame will be automatically initiated by the web driver. You only need to pass the right ID of the Frame. On my page i have only 1 Frame and that means = 0.

_WD_Window($sSession, 'frame', '{"id":0}')
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//p')
    _WD_ElementAction($sSession, $sElement, 'click')

What i try as next step is to select the text inside the Frame, but still no success... ;-)

BR

Link to comment
Share on other sites

I don´t know, why the WD does not return the string that i placed

1. i switch into the iframe

2.i execute the JS Script to receive the Text...

value is anytime NULL

Func _pasteIntoText() ;im Editor Texte markieren
    $sSearchtext = GUICtrlRead($Input1);--> document.getElementsByTagName('p')[0].innerHTML;
    $sStrategy = GUICtrlRead($Input2) ;--> empty

    _WD_Window($sSession, 'frame', '{"id":0}')

    $sElemtent = _WD_ExecuteScript($sSession, $sSearchtext, $sStrategy)

    _WD_Window($sSession, 'parent', '{"id":0}')
EndFunc   ;==>_pasteIntoText
<iframe allowfullscreen="true" src="javascript:false" style="width: 508px; height: 311px;" tabindex="3" frameborder="0">
<html>
  <head>
    <style>.ie * {min-height: auto !important} .ie table td {height:15px}</style>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
  </head>
  <body dir="ltr" contenteditable="true">
    <p align="center">test</p>
  </body>
</html>
  </iframe>
__WD_Post: URL=HTTP://127.0.0.1:4444/session/b0688555-6204-4ff2-a10f-75b44adda672/execute/sync; $sData={"script":"document.getElementsByTagName('p')[0].innerHTML;", "args":[]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ExecuteScript: {"value":null}

BR

horphi

Edited by horphi
Link to comment
Share on other sites

20 hours ago, Danp2 said:

You aren't returning a value from your script. Therefore, the result is null.

Your´re right...forgot to state "return" :lol:

return document.getElementsByTagName('p')[3].innerHTML;
__WD_Post: URL=HTTP://127.0.0.1:4444/session/b15514ad-6d2e-4c76-94b4-b35a542620b6/execute/sync; $sData={"script":"return document.getElementsByTagName('p')[3].innerHTML; ", "args":[]}
__WD_Post: StatusCode=200; ResponseText={"value":"[attach]"}

Did you tested to get a array back instead of a string? If i look for a specific value, then i need to execute the script several times, until i find the right one..

Or lets say, @ the END i will "select" the given value.

Normally:

return document.getElementsByTagName('p')[3].select;

--> but nothing happens... :-(

BR

Edited by horphi
Link to comment
Share on other sites

43 minutes ago, horphi said:

Did you tested to get a array back instead of a string? If i look for a specific value, then i need to execute the script several times, until i find the right one.

No, I haven't. Can you provide an example that shows what you are attempting to do?

P.S. If you are trying to return an array of elements, then you should look at _WD_FindElement

Link to comment
Share on other sites

Have I found an error in the code? I am under the impression that WD_FindElement will return an array so I am assuming that part might work at least it was stated by the code author. But using $_WD_LOCATOR_ByClassName seems incomplete. WD_Post doesn't seem to have a clue how to process the request.  My project is 90% complete and I can't get past this point. I have to find some way to generate a list of elements and somehow sequence through them. Thanks for any help.


$checkboxarray = _WD_FindElement($sSession, $_WD_LOCATOR_ByClassName, "x-tree-checkbox")

_ArrayDisplay($checkboxarray)

 

__WD_Post: URL=HTTP://127.0.0.1:4444/session/56d9c46d-6959-473b-980c-22830313d944/element; $sData={"using":"class name","value":"x-tree-checkbox"}
__WD_Post: StatusCode=400; ResponseText={"value":{"error":"invalid argument","message":"Unknown locator strategy class name","stacktrace":""}}
_WD_FindElement: {"value":{"error":"invalid argument","message":"Unknown locator strategy class name","stacktrace":""}}
_WD_FindElement ==> Webdriver Exception: HTTP status = 400

 

Link to comment
Share on other sites

Not an error in the code, per se. Looking at the latest W3C specs, these are the only supported locator strategies --

Quote
State Keyword
CSS selector "css selector"
Link text selector "link text"
Partial link text selector "partial link text"
Tag name "tag name"
XPath selector "xpath"

So, passing one of the other locator constants will result in the error you received.

I'll need to do some research to determine if these need to be removed or if they are valid in other instances.

Link to comment
Share on other sites

3 hours ago, BobMerit said:

I am under the impression that WD_FindElement will return an array so I am assuming that part might work at least it was stated by the code author.

Actually, it will return an array, but only if $lMultiple is True. If not, then it returns a single element id.

Here's one way that you could try rewriting your code to use xpath --

$checkboxarray = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".x-tree-checkbox", "", True)
_ArrayDisplay($checkboxarray)

 

Link to comment
Share on other sites

I certainly appreciate your response. It did change the error message. I seem to be pushing the limit of what can be done.

  $checkboxarray = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".x-tree-checkbox", "", True)
   _ArrayDisplay($checkboxarray)

__WD_Post: URL=HTTP://127.0.0.1:4444/session/171a5d58-3d1e-4fc7-8843-5363915d5e72/elements; $sData={"using":"xpath","value":".x-tree-checkbox"}
__WD_Post: StatusCode=400; ResponseText={"value":{"error":"invalid selector","message":"Given xpath expression \".x-tree-checkbox\" is invalid: SyntaxError: The expression is not a legal expression.","stacktrace":"WebDriverError@chrome://marionette/content/error.js:178:5\nInvalidSelectorError@chrome://marionette/content/error.js:336:5\nfind_@chrome://marionette/content/element.js:376:11\nelement.find/</findElements<@chrome://marionette/content/element.js:317:17\nevalFn@chrome://marionette/content/sync.js:86:7\nPollPromise/<@chrome://marionette/content/sync.js:101:5\nPollPromise@chrome://marionette/content/sync.js:81:10\nelement.find/<@chrome://marionette/content/element.js:316:24\nelement.find@chrome://marionette/content/element.js:315:10\nfindElementsContent@chrome://marionette/content/listener.js:1170:19\ndispatch/</req<@chrome://marionette/content/listener.js:489:14\ndispatch/<@chrome://marionette/content/listener.js:484:15\n"}}
_WD_FindElement: {"value":{"error":"invalid selector","message":"Given xpath expression \".x-tree-checkbox\" is invalid: SyntaxError: The expression is not a legal expression.","stacktrace":"WebDriverError@chrome://marionette/content/error.js:178:5\nInvalidSelectorError@chrome://marionette/content/error.js:336:5\nfind_@chrome://marionette/content/element.js:376:11\nelement.find/</findElements<@chrome://marionette/content/element.js:317:17\nevalFn@chrome://marionette/content/sync.js:86:7\nPollPromise/<@chrome://marionette/content/sync.js:101:5\nPollPromise@chrome://marionette/content/sync.js:81:10\nelement.find/<@chrome://marionette/content/element.js:316:24\nelement.find@chrome://marionette/content/element.js:315:10\nfindElementsContent@chrome://marionette/content/listener.js:1170:19\ndispatch/</req<@chrome://marionette/content/listener.js:489:14\ndispatch/<@chrome://marionette/content/listener.js:484:15\n"}}
_WD_FindElement ==> Webdriver Exception: HTTP status = 400

Link to comment
Share on other sites

15 minutes ago, BobMerit said:

I seem to be pushing the limit of what can be done

Not really... just have to get the syntax right. I likely steered you in the wrong direction because that's actually a CSS selector. Try changing $_WD_LOCATOR_ByXPath to $_WD_LOCATOR_ByCSSSelector.

If that doesn't work, then you should probably share more details about the element(s) you are attempting to locate (show us the associated HTML).

Link to comment
Share on other sites

Hi,

i´m irritated

this works

_WD_ExecuteScript($sSession, 'return  document.getElementsByTagName('p')[1].innerHTML;')

__WD_Post: URL=HTTP://127.0.0.1:4444/session/fc4b43b3-2c7b-4ce1-92fb-660e2d017aab/execute/sync; $sData={"script":"return  document.getElementsByTagName('p')[1].innerHTML; ", "args":[[]]}
__WD_Post: StatusCode=200; ResponseText={"value":"test2"}
_WD_ExecuteScript: {"value":"test2"}

But this not LINK

_WD_ExecuteScript($sSession, 'document.getElementsByTagName('p')[1].select;')

__WD_Post: URL=HTTP://127.0.0.1:4444/session/fc4b43b3-2c7b-4ce1-92fb-660e2d017aab/execute/sync; $sData={"script":" document.getElementsByTagName('p')[1].select; ", "args":[[]]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ExecuteScript: {"value":null}

Can someone explain to me what i don´t understand again???

Many thanks

horphi

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...