Jump to content
Danp2

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

Share this post


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

 

Share this post


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

Share this post


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

Share this post


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

Share this post


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

 

Share this post


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

 

Share this post


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

 

Share this post


Link to post
Share on other sites

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") & "<")

 

Share this post


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

Share this post


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

 

Share this post


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


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


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


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • 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/
      WebDriver for desired browser
      Chrome WebDriver https://sites.google.com/a/chromium.org/chromedriver/downloads FireFox WebDriver https://github.com/mozilla/geckodriver/releases Function List
      Core Functions
      _WD_CreateSession($sDesiredCapabilities='{}') _WD_DeleteSession($sSession) _WD_Status() _WD_Timeouts($sSession, $sTimeouts = '') _WD_Navigate($sSession, $sURL) _WD_Action($sSession, $sCommand) _WD_Window($sSession, $sCommand, $sOption = '') _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement = "", $lMultiple = False) _WD_ElementAction($sSession, $sElement, $sCommand, $sOption='') _WD_ExecuteScript($sSession, $sScript, $sArguments="[]") _WD_Alert($sSession, $sCommand, $sOption = '') _WD_GetSource($sSession) _WD_Cookies($sSession, $sCommand, $sOption = '') _WD_Option($sOption, $vValue = "") _WD_Startup() _WD_Shutdown() Helper Functions
      _WD_NewTab($sSession, $lSwitch = True, $iTimeout = -1, $sURL = "", $sFeatures = "") _WD_Attach($sSession, $sString, $sMode = 'title') _WD_LinkClickByText($sSession, $sText, $lPartial = True) _WD_WaitElement($sSession, $sElement, $sStrategy, $sSelector[, $iDelay = 0[, $iTimeout = -1]]) _WD_GetMouseElement($sSession) _WD_GetElementFromPoint($sSession, $iX, $iY) _WD_LastHTTPResult() _WD_GetFrameCount() _WD_IsWindowTop() _WD_FrameEnter($sIndexOrID) _WD_FrameLeave() _WD_HighlightElement($sSession, $sElement[, $iMethod = 1]) _WD_HighlightElements($sSession, $aElements[, $iMethod = 1]) _WD_jQuerify($sSession) WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "") _WD_ConsoleVisible($lVisible = False) Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/
    • By Davidowicza
      Hey guys,
      I am creating my very first script that automates a browser (I usually work with program installs and database automation) and have come across an issue that I am totally stumped on. I need to click an element that gives me a drop down list box but the Xpath to the element changes with every instance of chrome I start...
      I have tried selecting the class, rect, and path but no luck. It never finds the element. (I could be doing this wrong since I am not good at HTML)
      Element I need to select:
      This is the Xpath for the last 3 instances of chrome I have run the script with:
      //*[@id="highcharts-5bp9crq-8"]/svg/g[6]/g/rect //*[@id="highcharts-fiw9szv-8"]/svg/g[6]/g/rect //*[@id="highcharts-5szkmx8-8"]/svg/g[6]/g/rect As you can see the path changes every time.
      How I am trying to select the element:
      ;Check for box element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") MsgBox(0, "", "check for timeout") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") _WD_ElementAction($sSession, $sElement, 'click') Maybe someone has come across this before and found a work around without using mouseclick()
      Thanks guys, hopefully I am just very overlooking something simple and can be pointed to the right solution.
      Side Note: I wish I could share the webpage entirety, but it has sensitive information with my agency that I cannot share. If you need more, just let me know and I will try and post as much as I can.
    • By daluu
      This is kind of already posted here:
      '?do=embed' frameborder='0' data-embedContent>>
      but wanted to note this in this forum of example scripts in case some people only look in this forum for examples and not the other forums with respect to AutoIt integration or relation to Selenium WebDriver.
      So, the example in summary is: you can use Selenium WebDriver API to do AutoIt GUI automation (the ControlXyz() and WinXyz() functons, along with mouse and "send keys" functions). Although I suppose that might be opposite or counter to what most examples here are about - using AutoIt to do or control other stuff rather than using other stuff to control/run AutoIt. But regardless, it is an example implementation of a different use case for AutoIt beyond the general AutoIt community, like those who also use Selenium WebDriver and/or need to integrate Selenium with AutoIt for remote deployment.
      https://github.com/daluu/AutoItDriverServer
      with specific demo examples here:
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/CalculatorTest.java
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/calculator.py
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationTest.java
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationWithAutoItDriver.py
×
×
  • Create New...