Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

4 hours ago, Danp2 said:

In this situation, you have to pass the attribute or property name using the proper case. The process is returning a Null because it can't find an attribute named "innerhtml". Change this to "innerHTML" and it should give you the desired result.

Thanks Danp2! This solved the issue 👍

Link to comment
Share on other sites

On 12/15/2019 at 12:38 AM, jbnet said:

Gostaria de saber se é possível acessar esses recursos de rede após carregar a página no firefox conforme definido na imagem com o webdriver Tentei enviar o comando javascript, enviar sequência de cabeçalho mas com minha pouca experiência não consegui obter esses dados como a imagem, mas quero que ele recupere os dados como exemplo na imagem, essa lista de pedidos, mas não sei como fazer. Agradeço esse trabalho, gosto muito desse udf.

HeaderFirefox.thumb.png.034653eb9d77b27e0bafc9c1fe1e44d6.png

Danp2 I had asked you this question, but you didn't understand, I wanted to get the network data that was in firefox, based on the stackoverflow website https://stackoverflow.com/questions/45847035/using-selenium-how-to-get-network-request, I did it using javascript, but it shows how to do it with seleneium webdriver, using javascript and java, but looking at the site, would you have an idea of how to implement in autoit using webdriver without javascript?

Edited by jbnet
Link to comment
Share on other sites

So I use your script more, my knowledge is little to implement, but the data I use is, for example, the link I get on the network, xhr, where I can't find it on the page, an example I'm using, in json format then I look for what I need inside.

$txt =_WD_ExecuteScript($sSession, _
        "var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {}; var network = performance.getEntries() || {}; return JSON.stringify(network);" ) 
    ;clipPut($txt)
    Local $obJson = Json_Decode($txt)
    $obJson = Json_Decode(Json_ObjGet($obJson, "value"))
Link to comment
Share on other sites

  • 2 weeks later...
#include "wd_helper.au3"
#include "wd_core.au3"

#AutoIt3Wrapper_UseX64=Y  
OnAutoItExitRegister("_onExit")

$_WD_DEBUG =  True ; You could also use $_WD_DEBUG_Error

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

$sDesiredCapabilitiesNoSecurNoConsole = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--disable-web-security", "--incognito", "--user-data-dir=C:\\Temp", "--profile-directory=Default"]}}}}'


_WD_Startup()

If @error <> $_WD_ERROR_Success Then MsgBox(0,'','error')


global $sSession = _WD_CreateSession($sDesiredCapabilitiesNoSecurNoConsole)     ;~  session not created: This version of ChromeDriver only supports Chrome

Exit



Func _onExit()
    ConsoleWrite("####")
    _WD_DeleteSession($sSession)
   
    ConsoleWrite("deleteSess: " & @error & " " & @extended & @CRLF)

    _WD_Shutdown()

EndFunc ; end onexit

_WDStartup: OS: WIN_10 WIN32_NT 18362
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.3.0.8 (Update available)
_WDStartup: WinHTTP:    1.6.3.9 (Download latest source at <https://raw.githubusercontent.com/dragana-r/autoit-winhttp/master/WinHttp.au3>)
_WDStartup: Driver: chromedriver.exe


It seems there is a problem with
_WD_DeleteSession

it does not execute the next _WD_Shutdown (neither the Consolewrite after the Delete...)!

I found it blocks on

__WD_DetectError on this line:

Local $oJSON = Json_Decode($vResult)  ( $vResult is {"value":null} )

and in the Json_Decode func at the line:

DllCallAddress("none:cdecl", $Jsmn_Init, "ptr", DllStructGetPtr($Parser))

it seems it crashes the script...


EDIT:

I don't know why the editor does not align the text correctly... sorry (in the preview is correct)

Edited by Melba23
Fixed formatting
Link to comment
Share on other sites

59 minutes ago, frank10 said:

_WDStartup: WinHTTP:    1.6.3.9 (Download latest source at <https://raw.githubusercontent.com/dragana-r/autoit-winhttp/master/WinHttp.au3>)

This is here for your benefit. Please follow the directive and then retest once you are on v1.6.4.2.

P.S. Since you aren't running v1.6.4.1, I would recommend installing that first and then grab the latest source at the link above

Link to comment
Share on other sites

1 hour ago, frank10 said:

It seems there is a problem with _WD_DeleteSession

it does not execute the next _WD_Shutdown (neither the Consolewrite after the Delete...)!

This isn't an area where I have a ton of experience, but I'm guessing that this is a timing issue with the _onExit function being called after some global variables have been destroyed. Perhaps someone else will jump in with some ideas on how this can be resolved.

Link to comment
Share on other sites

@frank10 and anyone else interested,

Here's a simple reproducer script --

#include <JSON.au3> ; https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn

#AutoIt3Wrapper_UseX64=Y
OnAutoItExitRegister("_onExit")

Demo()
Sleep(2000)

Func _onExit()
    Demo()
EndFunc

Func Demo()
    Local $sJSON = '{"value":null}'
    ConsoleWrite("pre Json_Decode" & @CRLF)
    Local $oJSON = Json_Decode($sJSON)
    ConsoleWrite("post Json_Decode" & @CRLF)
EndFunc

If you comment out the call to Demo() in the main script, then the crash no longer occurs. Guessing that it has something to do with the static variable usage,.

Link to comment
Share on other sites

2 hours ago, Danp2 said:

If you comment out the call to Demo() in the main script, then the crash no longer occurs.

It also does not occur if you move the registering of _OnExit() AFTER Demo() in the main script.  It looks like as long as OnAutoITExitRegister() is NOT the first function called in the script, it works fine.

#include <JSON.au3>

Demo()
OnAutoItExitRegister("_onExit")
Demo()

Func _onExit()
    Demo()
EndFunc

Func Demo()
    Local $sJSON = '{"value":null}'
    ConsoleWrite("pre Json_Decode" & @CRLF)
    Local $oJSON = Json_Decode($sJSON)
    ConsoleWrite("post Json_Decode" & @CRLF)
EndFunc

 

Edited by TheXman
Link to comment
Share on other sites

@Danyfirex has identified that the issue originates in the BinaryCall UDF, which gets called by the JSON UDF. It registers an OnAutoITExitRegister function, that is freeing resources before the main OnAutoITExitRegister function gets executed.

@TheXman Your example works because it registers the BinaryCall exit routine before the main OnAutoITExitRegister routine is registered, so exit events now occur in the desired order. You can also accomplish this by adding the following before calling OnAutoITExitRegister

Json_Decode("")

Will release an update to the UDF once we come up with a more permanent fix.

Link to comment
Share on other sites

Hello, I am trying to run two different scripts using chrome webdriver. Apps are run from different folders using different locations for chromedriver.exe. These are apps for testing. They will only navigate to different pages. After I start second app first one closes immediately if I use same port. If I change one port to something different than 9515, i.e. 4444, then I get following output:

_WD_IsLatestRelease: True
_WD_IsLatestRelease ==> Success
_WDStartup: OS:    WIN_10 WIN32_NT 18362 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.3.0.9 (Up to date)
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver:    chromedriver.exe
_WDStartup: Params:    
_WDStartup: Port:    4444
__WD_Post: URL=HTTP://127.0.0.1:4444/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}
__WD_Post: StatusCode=0; ResponseText=WinHTTP request timed out before Webdriver...
__WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_CreateSession: WinHTTP request timed out before Webdriver
_WD_CreateSession ==> Webdriver Exception: HTTP status = 0
create session:10

 

I am also attaching screenshot of chromedriver window. As can be seen it shows "Starting... on port 9515" altough something else is defined in script.

 

image.png

app1.au3 app2.au3

Edited by ahmet
Link to comment
Share on other sites

@Danp2 Thank you. This is the code I used

_WD_Option('DriverParams', '--port=9815')

It did start webdriver on different port, but the chromedriver.exe's window kept closing as soon as I launch second app, so I was only able to use one app. I solved it by renaming one of chromedriver.exe files to something else, test.exe in this case, and then they are running well. I am also using different ports.

Edit: If I use same ports, but rename one of chromedriver.exe files then two scripts also work.

Edited by ahmet
Link to comment
Share on other sites

@ahmet I forgot to mention that this is the default behavior and there are additional setttings that you will need to adjust. Add this to the beginning of your script to prevent it from closing an existing webdriver instance and force it to launch a second instance --

_WD_Option("driverclose", False)
_WD_Option("driverdetect", False)

 

 

Link to comment
Share on other sites

I dread every time I have edit the  "capabilities" when I am using the Chromedriver.
Is there some clear explanation with plenty😁 of examples available ? 
Big Wish: is there an app or a website where one could just select the capabilities and the string would be created to copy to AutoIt ?

 

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