Jump to content

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

Link to comment
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.

 

Link to comment
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

Link to comment
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...

Link to comment
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 ?

Link to comment
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 ?

 

Link to comment
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

 

Link to comment
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 ?

 

Link to comment
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 !
 

Link to comment
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}}<

 

Link to comment
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 :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
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.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...