Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

1 hour ago, Danp2 said:

@Clayson Poste seu código revisado para que eu possa ver suas alterações.

FWIW, estou no processo de escrever a função _WD_ElementActionEx, que permitirá que você faça coisas como essa com mais facilidade. No momento, eu tenho codificação para essas ações: hover, dblclick e rgtclick. Vou adicionar mais como penso neles ou receber sugestões.

 The code is 

 $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='tableEqpAtrib']/tbody/tr/td")
          If @error = $_WD_ERROR_Success Then

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

 funtional but slow ! Duration of click 1 second , in this case 5 seconds, illustrative only... no errors found!!!!!

 

      This development that is proposed will be very relevant to improve the use of autoit with webdriver. The question of performance is clearer using selenium, I did not go deeper because I want to do it for autoit and improve this integration that I find more complete since we will not always deal with browsers only.

thanks

 

Link to comment
Share on other sites

3 minutes ago, Danp2 said:

@Clayson That code appears to be unchanged to me. What exactly are you stating is causing this perceived slowdown?

P.S. I believe the admin's would prefer that you not quote text in a foreign language. Plus I have no idea what it says without running it back through a translator. 🤣

Sorry for the quote, I'm translating the site so as not to be betrayed by my understanding of English, I didn't know that it remained translated kkkkk.

Exactly, your code was perfect, I didn't change anything and it already worked, but following each step it stops for a longer time when executing this step, when it goes to the others that is just a click is very fast. I didn't understand why he takes longer than the others, but it certainly happens.

There are no error messages as I have already commented only slowly.

thanks!

Link to comment
Share on other sites

@stephan111 Welcome to the forum.

It's always helpful if you can provide context along with your question. What website / service are you needing to interact with, and why would you need to submit a POST request via the webdriver?

P.S. If you want to submit a regular POST request, then use the functions from the WinHTTP UDF.

Link to comment
Share on other sites

@Danp2 Thank you for your fast response.

I want to send a POST request in browser context because cookies are used. So WinHTTP is not possible.

I could not find an example how to send a POST request via _WD_ functions.

I can get the needed data with this js but I don't know how to get the value back to my script:

$.post( '/?getfile=account_logic', { getaccount: '1'} );

I tested many things. This script works:

_WD_ExecuteScript($sSession, "function getBalance() { var balance = window.location.href; return balance;} return getBalance();")

But I don't know how to use $.post or $.ajax in the right way.

Thanks

Link to comment
Share on other sites

On 6/16/2020 at 8:26 AM, Clayson said:

Sorry for the quote, I'm translating the site so as not to be betrayed by my understanding of English, I didn't know that it remained translated kkkkk.

Exactly, your code was perfect, I didn't change anything and it already worked, but following each step it stops for a longer time when executing this step, when it goes to the others that is just a click is very fast. I didn't understand why he takes longer than the others, but it certainly happens.

There are no error messages as I have already commented only slowly.

thanks!

@Danp2 Thanks for your help! This problem has been solved, it is not slow anymore. I did not understand the reason, but the slowness does not repeat in the last days, there were windows updates in the period could be that.

I saw your code on github, congratulations _WD_ElementActionEx is the best option for this case in my humble opinion.


My current development is basically in chrome with a database, so I will still explore a lot of options including actually using the _WD_ElementActionEx in development and I will return on the use.

Link to comment
Share on other sites

So maybe someone here could help me figure out how to disable javascript when using Chrome. I've tried this to no avail

{"capabilities": {"javascriptEnabled":false, "alwaysMatch": {"unhandledPromptBehavior": "ignore", "goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], "useAutomationExtension": false, "args": ["start-maximized", "headless"]}}}}

There is tons of help using other languages about web driver but with AutoIt, it seems rather sparse with info about how to go upon controlling webdriver through http requests.

Any ideas?

Edited by Jos
Moved to the support thread.
Link to comment
Share on other sites

I think that you are going to be disappointed because it appears that you can't disable javascript and run headless at the same time. Here's a working example without headless --

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

Local $sDesiredCapabilities, $sSession
SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.whatismybrowser.com/detect/is-javascript-enabled")
$sScreenShot = _WD_Screenshot($sSession)
$hFileOpen = FileOpen("Screen1.png", $FO_BINARY + $FO_OVERWRITE)
FileWrite($hFileOpen, $sScreenShot)
FileClose($hFileOpen)

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, "args":["start-maximized", "disable-infobars"], "prefs": {"profile.default_content_setting_values.javascript": 2}}}}}'
EndFunc

To see that it doesn't work as headless, add back the headless argument, rerun the script, and then examine the screenshot.

Link to comment
Share on other sites

On 6/18/2020 at 11:38 AM, Clayson said:

@Danp2 Thanks for your help! This problem has been solved, it is not slow anymore. I did not understand the reason, but the slowness does not repeat in the last days, there were windows updates in the period could be that.

I saw your code on github, congratulations _WD_ElementActionEx is the best option for this case in my humble opinion.


My current development is basically in chrome with a database, so I will still explore a lot of options including actually using the _WD_ElementActionEx in development and I will return on the use.

 @Danp2 Good Afternoon  !

I have a problem with that code for the doubleclick. It works well several times and suddenly stops working. No apparent error message. I read something about the doubleclick difficulty on chromedriver but nothing illuminating. Can you help me? The code remained unchanged because it worked well, it was fast and without crashes. There is no change in the code or actions that it causes, it is the same element that always clicks and I do not change that part of the code. 

Thanks,  

 local $sButton
         $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='tableEqpAtrib']/tbody/tr/td")
                  sleep (2000) ;aguarda um tempo

         $sAction = '{"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":300,"y":200,"type":"pointerMove","origin":{"ELEMENT":"'
         $sAction &= $sButton & '","' & $_WD_ELEMENT_ID & '":"' & $sButton & '"}},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"}]}]}'
         _WD_Action($sSession, "actions", $sAction); CONFIRMA SELEÇÃO DA EQUIPE
                  sleep (4000) ;aguarda um tempo

 

no console appear :

 

__WD_Post: URL=HTTP://127.0.0.1:9515/session/99114ddbaf39b147261b58bd9b10ec9d/element; $sData={"using":"xpath","value":"//*[@id='tableEqpAtrib']/tbody/tr/td"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"dcd3fd4d-940c-4ba8-bee1-7d77c8b568d4"}}...
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"dcd3fd4d-940c-4ba8-bee1-7d77c8b568d4"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/99114ddbaf39b147261b58bd9b10ec9d/actions; $sData={"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":300,"y":200,"type":"pointerMove","origin":{"ELEMENT":"dcd3fd4d-940c-4ba8-bee1-7d77c8b568d4","element-6066-11e4-a52e-4f735466cecf":"dcd3fd4d-940c-4ba8-bee1-7d77c8b568d4"}},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"}]}]}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Action: {"value":null}

Edited by Clayson
Link to comment
Share on other sites

54 minutes ago, Clayson said:

 @Danp2 Good Afternoon  !

I have a problem with that code for the doubleclick. It works well several times and suddenly stops working. No apparent error message. I read something about the doubleclick difficulty on chromedriver but nothing illuminating. Can you help me? The code remained unchanged because it worked well, it was fast and without crashes. There is no change in the code or actions that it causes, it is the same element that always clicks and I do not change that part of the code. 

Thanks,  

 local $sButton
         $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='tableEqpAtrib']/tbody/tr/td")
                  sleep (2000) ;aguarda um tempo

         $sAction = '{"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":300,"y":200,"type":"pointerMove","origin":{"ELEMENT":"'
         $sAction &= $sButton & '","' & $_WD_ELEMENT_ID & '":"' & $sButton & '"}},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"}]}]}'
         _WD_Action($sSession, "actions", $sAction); CONFIRMA SELEÇÃO DA EQUIPE
                  sleep (4000) ;aguarda um tempo

 

no console appear :

 

__WD_Post: URL=HTTP://127.0.0.1:9515/session/99114ddbaf39b147261b58bd9b10ec9d/element; $sData={"using":"xpath","value":"//*[@id='tableEqpAtrib']/tbody/tr/td"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"dcd3fd4d-940c-4ba8-bee1-7d77c8b568d4"}}...
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"dcd3fd4d-940c-4ba8-bee1-7d77c8b568d4"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/99114ddbaf39b147261b58bd9b10ec9d/actions; $sData={"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":300,"y":200,"type":"pointerMove","origin":{"ELEMENT":"dcd3fd4d-940c-4ba8-bee1-7d77c8b568d4","element-6066-11e4-a52e-4f735466cecf":"dcd3fd4d-940c-4ba8-bee1-7d77c8b568d4"}},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"}]}]}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Action: {"value":null}

In complement,  i'm aply   a code whith _WD_ElementActionEx, in this case 

 

 _WD_ElementActionEx($sSession, $sButton, 'doubleclick', 300, 200)  but this response is "Sucess" but no sucess.

in console

__WD_Post: URL=HTTP://127.0.0.1:9515/session/e6839ced38bb8d3c1928327060bdcd2d/element; $sData={"using":"xpath","value":"//*[@id='tableEqpAtrib']/tbody/tr/td"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"50a0603c-b227-4668-b877-bccb422ca3a1"}}...
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"50a0603c-b227-4668-b877-bccb422ca3a1"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/e6839ced38bb8d3c1928327060bdcd2d/actions; $sData={"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":300,"y":200,"type":"pointerMove","origin":{"ELEMENT":"50a0603c-b227-4668-b877-bccb422ca3a1","element-6066-11e4-a52e-4f735466cecf":"50a0603c-b227-4668-b877-bccb422ca3a1"}},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"}]}]}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Action: {"value":null}
_WD_ElementActionEx ==> Success

 

 


but despite the answer being "Sucess", he did not take action.
as I mentioned in the previous  intermittent post, today it didn't work, just the doubleclick.

thanks

Link to comment
Share on other sites

11 minutes ago, Danp2 said:

@Clayson Difficult to say since we can't test your script. Perhaps to website changed their coding? <shrug>

Have you tried running the example code I previously posted?

 

Yes it is the same coding on the website: (....
My code is the same as the example, this control is found, this action returns a message successfully, but it doesn't work in practice.

Link to comment
Share on other sites

Good evening,

I'm struggling with a (if its done manually) very simple think: visite a website and download some files. Please find below my code and the error log.

I'm using following Versions:

AutoIt 3.3.14.5

Firefox: 77.0.1 (64 Bit)

Geckodriver 0.26 (64 Bit)

WinHttp 1.6.4.1

Json: 2019.01.17

WebDriver 0.3.0.3

#include "wd_core.au3"
#include "wd_helper.au3"
 local $arr[6]
 $arr[0] = "https://file-examples.com/wp-content/uploads/2017/02/file-sample_100kB.doc"
 $arr[1] = "https://file-examples.com/wp-content/uploads/2017/02/file-sample_500kB.doc"
 $arr[2] = "https://file-examples.com/wp-content/uploads/2017/02/file-sample_1MB.doc"
 $arr[3] = "https://file-examples.com/wp-content/uploads/2017/02/file-sample_100kB.docx"
 $arr[4] = "https://file-examples.com/wp-content/uploads/2017/02/file-sample_500kB.docx"
 $arr[5] = "https://file-examples.com/wp-content/uploads/2017/02/file-sample_1MB.docx"

Global $sDriver = "C:\temp\geckodriver.exe"
Global $sDesiredCapabilities, $sSession, $sScriptName = "Testing download", $aResult_All
$_WD_DEBUG = $_WD_DEBUG_Error

_WD_Option("Driver", $sDriver)
If @error Then Exit SetError(1, @error)
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)
$sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true}}'

_WD_Startup()
 $sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Window($sSession, "Maximize")
_WD_Navigate($sSession, "https://file-examples.com/index.php/sample-documents-download/sample-doc-download/")


For $i = 0 to 5
 _WD_Navigate($sSession,$arr[$i])
 WinActivate("[CLASS:MozillaDialogClass]")
 sleep(10)
 Send("{ALTDOWN}")
 Sleep(10)
 Send("s")
 Sleep(10)
 Send("{ALTUP}")
 Send("{ENTER}")
 Sleep(100)
Next
msgBox(1,"Status","everything done")

Error Log

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\temp\download_test.au3" /UserParams    
+>00:53:27 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (4.2.0.0)  Keyboard:00000407  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0407)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\name\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\name\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\temp\download_test.au3
+>00:53:27 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\download_test.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
_WDStartup: "C:\temp\geckodriver.exe" --log trace 
__WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_Navigate ==> Send / Recv error: HTTP status = 0
__WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_Navigate ==> Send / Recv error: HTTP status = 0
__WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_Navigate ==> Send / Recv error: HTTP status = 0
__WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_Navigate ==> Send / Recv error: HTTP status = 0
__WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_Navigate ==> Send / Recv error: HTTP status = 0
__WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_Navigate ==> Send / Recv error: HTTP status = 0
+>00:56:51 AutoIt3.exe ended.rc:0
+>00:56:51 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 205.1
Link to comment
Share on other sites

On 6/25/2020 at 4:36 PM, Danp2 said:

@Clayson My question was "Have you tried running the example code I previously posted?" and then I shared the link. From your response, it isn't clear if you ran this example code and did it function correctly.

@Danp2 Yes, I did .

But after that, I identified a problem that seems to be in the compilation of the program or in an execution in the SCITe editor, if I close all the scripts, close the editor and open it again, this problem is interrupted, but at another time it resurfaces and I repeat the closing process . I started using ISN Autoit Studio and it happens less often but it was still repeated. But just closing and reopening the script and not the IDE has already solved it.
I don't know why when the error occurs, it interrupts just at double-click and not any other point.

thanks.

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...