Jump to content

WebDriver UDF - Help & Support


Recommended Posts

Hi guys,

First time writing in the forum. Great job for the WebDriver UDF.

Now I know that somewhere I read something about this, but since I was not sure if it's the same case I will ask here again. If it's against some policies just let me know.

Currently I want to automate some processes, but because one of the sites requires(have a pop-up) for certificate, I don't know how to interact with it. I just need to click on the OK button when it came out(if possible to not use Send("{ENTER}")):

image.png.c8888447cd97bc7229c9bf3e19baaaea.png

I will appreciate if somebody can help or advise on the matter. I have already tried to research this by myself by I didn't find a solution.

Thanks in advance.

Link to comment
Share on other sites

On 3/1/2019 at 11:48 AM, danylarson said:

Hi Dan,

For example in the website : https://www.airbnb.fr/

I m trying to select a value on a single choice  select box 

$MySelectBox = "//select[@id='adults']"

$MyElement = _WD_FindElement($SessionId, $_WD_LOCATOR_ByXPath, $MySelectBox)

_WD_ElementAction($SessionId, $MyElement , 'Value',"2 adultes")

It doesn t work

Can you tell us how we can do to  fill a select box with a value ?

Thanks for all

 



I forgotten the stack trace : 

_WD_ElementAction ==> Webdriver Exception: {"value":{"error":"unknown error","message":"'value' must be a list

Thanks for your explanations

 

Link to comment
Share on other sites

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

Local $aDemoSuite[][2] = [["DemoTimeouts", False], _
                        ["DemoNavigation", false], _
                        ["DemoElements", true]  ]

Local Const $sElementSelector = "//input[@name='q']"

Local $sDesiredCapabilities
Local $iIndex
Local $sSession

$_WD_DEBUG = $_WD_DEBUG_Info



SetupChrome()
_WD_Startup()
If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

$sSession = _WD_CreateSession($sDesiredCapabilities)
Call($aDemoSuite[2][0])

Do
Sleep(100)
Until WinExists('Watch') = 0

_WD_DeleteSession($sSession)
_WD_Shutdown()



Func DemoElements()
    Local $sElement, $aElements, $sValue
    $URI1 =  'http://artsandculture.google.com/story/fQJiFTYiVkj2Ig'

    _WD_Navigate($sSession, $URI1)

    $src =_WD_GetSource($sSession)
    if StringInStr($src, 'yDmH0d') > 0 then
        for $i = 1 to 12
        $sElement = _WD_FindElement($sSession, _
                                                        $_WD_LOCATOR_ByXPath, _
                            '//*[@id="yDmH0d"]/div[3]/div[1]/content/div/div[1]/div/div[1]/div[3]/div[11]/img['& $i & ']')
        Next
    EndIf

    If @error = $_WD_ERROR_NoMatch Then
        Exit
    Else
    EndIf

    $sResponse = _WD_ElementAction($sSession, $sElement, 'click')
    $sJSON = Json_Decode($sResponse)
    $sResult = Json_Get($sJSON, "[value]")
    ConsoleWrite($sResult & @CRLF)
EndFunc


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

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

I'm new to web drivers and webpage automation. Many of your responses say to check if it's in correct format, but I got the xpath from Chrome's inspection tool. So my script is supposed to get the page source and confirm that the <body> has the said id attribute. Then, I want the return values of some heavily nested images. A strange thing to consider is the source code retrieved from WD_GetSource() doesn't have any blob links that are src for these <img>. But when I paste the source code into a HTML editor and it renders everything, and I inspect these <img> again, the blob links appears. I'm wondering if you can help me with this or maybe find out if my xpath is the only thing wrong.

Link to comment
Share on other sites

4 hours ago, Danp2 said:

@Relive I would suggest trying an xpath of "//img.XkWAb-LmsqOc" to retrieve the desired image elements. You should be able to grab them all by using the $lMultiple parameter with a single call to _WD_FindElement

Hi. I tried your suggestion and it looks like no values were returned. I have modified this portion of my code as shown 

;   for-loop was here
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//img.XkWAb-LmsqOc', '', true)    ;   200 and empty?

    _ArrayDisplay($sElement)
    if @error then ConsoleWrite('$sElement' & ' = ' & $sElement & @CRLF)

;   bottom of the code is original

Here is the SCITE output 

_WDStartup: OS: WIN_7 WIN32_NT 7600 
_WDStartup: AutoIt: 3.3.14.2
_WDStartup: WD.au3: 0.1.0.17
_WDStartup: Driver: nope
_WDStartup: Params: --log-path=nope
_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":"72.0.3626.121","chrome":{"chromedriverVersion":"2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1)","userDataDir":"C:\\Users\\nope~1\\AppData\\Local\\Temp\\scoped_dir1972_24080"},"goog:chromeOptions":{"debuggerAddress":"localhost:52534"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows nt","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"},"sessionId":"c3476d61b04ac2cf8f5965dbc2c553e1"}}
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"72.0.3626.121","chrome":{"chromedriverVersion":"2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1)","userDataDir":"C:\\Users\\nope~1\\AppData\\Local\\Temp\\scoped_dir1972_24080"},"goog:chromeOptions":{"debuggerAddress":"localhost:52534"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows nt","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"},"sessionId":"c3476d61b04ac2cf8f5965dbc2c553e1"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/c3476d61b04ac2cf8f5965dbc2c553e1/url; $sData={"url":"http://artsandculture.google.com/story/fQJiFTYiVkj2Ig"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/c3476d61b04ac2cf8f5965dbc2c553e1/elements; $sData={"using":"xpath","value":"//img.XkWAb-LmsqOc"}
__WD_Post: StatusCode=200; ResponseText={"value":[]}
_WD_FindElement: {"value":[]}
_WD_FindElement ==> No match: HTTP status = 200
$sElement =

 

Link to comment
Share on other sites

4 hours ago, Relive said:

I tried your suggestion and it looks like no values were returned. I have modified this portion of my code as shown  

The following works for me. Note the use of  _WD_WaitElement to allow the web page to completely load.

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

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

_WD_Startup()
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}'
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "http://artsandculture.google.com/story/fQJiFTYiVkj2Ig")

$sSelector = "//img[@class='XkWAb-LmsqOc']"
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $sSelector)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sSelector, '', True)

_WD_DeleteSession($sSession)
_WD_Shutdown()

 

Link to comment
Share on other sites

  • 3 weeks later...

Hi members,

First time writing in the forum. Great job for the WebDriver UDF.

In the last 2 days I try understand the functionality by playing with the Webdriver-Demo.au3 and reading the whole help & support dialog.

Many hours I am searching for a how to do to create actions for the mouse and keys, like enter, arrow-keys etc by the example of the demo:

$sAction = '{"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"'
$sAction &= $sElement & '","' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}},{"button":2,"type":"pointerDown"},{"button":2,"type":"pointerUp"}]}]}'

I do not found anything.

Can anybody give me a tip where I can find a description of the syntax, standard-id's, keywords, parameters etc. and examples of some ? 

Like the help of AutoIT

Please, not the W3C-documents. I did understand nothing, what they wrote.

Many thanks and regards

Link to comment
Share on other sites

@Hamburgo This is an advanced topic, so there aren't many examples of doing this with Autoit. Perhaps if you explained in detail what it is that you are attempting to accomplish, then we may be able to offer you a simpler route.

P.S. When in doubt, the W3C docs are the definitive authority for all things webdriver related. :thumbsup:

Link to comment
Share on other sites

@Danp2 Thanks for your answer.

For first, I do not needing a lot for my next process. I need to know the syntax of the actions, how to send key's like TAB, ENTER, DELETE, arrow key's etc and CTRL+C etc.

And I want to know the following:
The example in the demo taked a 2nd button-click to open a context menu. What will be full syntax of one command or the steps of a couple of command to do the full process, like open the contex-menu and select a item of the menu (for example "copy") by keyboard or mouse (I prefer keyboard, because I am a fan of the keyboard more than the mouse) ?

many thanks for your help

Link to comment
Share on other sites

@Hamburgo Technically, it isn't two button clicks. Instead think of this as a series of actions or events, where we send a mouse down event followed by a mouse up.

IMO, using _WD_Action should be your last option when attempting Webdriver automation. There are generally easier ways to accomplish tasks. The demo gives you the basic structure for using the function. If you choose to continue down this path, then you are on your own to figure out how to send the keystrokes.

Once you've figured it out, please post the code here so that others can benefit from your efforts. 🙂

Link to comment
Share on other sites

@Danp2 thanks for your answer.

As I wrote in my first post, I am so sorry not be able to figure out to send keystrokes by myself, because I do not have the skil to understand the W3C-documents and my english is not good enougth, to learn it. Otherwise, I will not ask for help.

So, my hope was, that anybody with experiences to send keystrokes to your webdriver will post to the forum a example of syntax for one or more key's.  To find the key-codes for other key's over google will be than easy.

Do you know a member with this skill ?
 



 

Link to comment
Share on other sites

2 hours ago, Hamburgo said:

Do you know a member with this skill ?

I'm sure there are several, including myself. However, you haven't given a good explanation or example of why you need to send keystrokes to a browser. If you would do that, then perhaps someone would feel inclined to help you further. 😉

 

Link to comment
Share on other sites

ok, I found a solution to send keystrokes, for example "backspace" or "tab"

 _WD_ElementAction($sSession, $sElement, 'value', "\uE003")

 _WD_ElementAction($sSession, $sElement, 'value', "\uE004")

My Project:
I want to sent a lot of data to big table of my own ERP-System based on PHP.

The data stored in a big file in a fixed order record by record.

My strategy was quiet simple.

Open the form with the table in my application, focus the first field, reading field by field of record by record and send the data for the field, send tab-key for switch to the next field by tabindex and after the last field click the save-button etc. up to end of file.

But, I believe, I have a mistake in my strategy.

To send the data throuth the field I found in your demo the command:

 _WD_ElementAction($sSession, $sElement, 'value', "Test-Eingabe 123")

This command needs to know $sElement and after the tab-key I do not know $sElement from the next field.

To get $sElement from the next field I will need a command like  "POST  /session/:sessionId/element/active"

I do not found a command like this in your UDF.

Is there a possibility to have it or a other way to follow my strategy?

Thanks and regards

Link to comment
Share on other sites

Thanks for explaining your goal, as this helps to see that you really don't needs to send keystrokes using the native Actions in Webdriver. Instead you should focus on processing the table's rows and columns to obtain the individual cells.

You can do this using _WD_FindElement with the $sStartElement equal to the desired table and the $lMultiple parameter set to True, which will result in an array of row (TR) elements. You can then repeat this once for each row element to get an array of cell (TD) elements. Use these along with _WD_ElementAction to set the value of the desired cells.

Link to comment
Share on other sites

@Danp2

Many thanks for your answer.

Your quote:
"Thanks for explaining your goal, as this helps to see that you really don't needs to send keystrokes using the native Actions in Webdriver."

Your quote will be correkt for all users of your UDF they will have the same hight skill as you have.

But I have to live with the restrictions of my head and I do not have the same hight level of skill as you and I am to old, to get it.

For me will be much easier to work as I explained. To follow your proposal will be possible, but for me a stressful way.

The question is: "What is your philosophy for this UDF ?"

Should it usefull for all users, they are interested in or only for users with near the same hight skill as you have ?

The first group will needing some other functions.

The reason for story of success of AutoIT is, because it is designed for the first and the second group and the documentation, too.

Thanks and regards

Link to comment
Share on other sites

@Hamburgo To answer your question, my goal of the UDF is to make automation via Webdriver easier for the average user. I believe that goal has been met. Can the UDF be expanded / enhanced further? Certainly! Same could be said for the examples / documentation.

I have attempted to show you the "preferred" way to tackle the described task, using methods that are known to work. My recommendation would be the same no matter your skill level.

It's your prerogative to use the UDF in any manner that you desire. But you are attempting to use an advanced feature of the Webdriver that isn't well documented AFAICS, so you will likely struggle to get it working on your own.

Perhaps we should just agree to disagree on our view points.  🤷‍♂️

Link to comment
Share on other sites

@Danp2 2 questions, I have:

1. I posted the command that I am figured out to send keystrokes. Do you know a better way ?

2. I am playing a little bit with this command and everything runs fine, including ctrl+c etc. Only ctrl+f will not do his job and will not open the search-field of FireFox. Do you know a reason ?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...