Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

@Aether and anyone else that feels like testing, here's a simple test script I've been using --

#include "WinHttp.au3"
#include <WinAPIError.au3>

Opt("MustDeclareVars", 1)

Global $sDomain = "www.github.com"
Global $sPage = "dragana-r/autoit-winhttp"

; Initialize and get session handle
Global $hOpen = _WinHttpOpen()
; Get connection handle
Global $hConnect = _WinHttpConnect($hOpen, $sDomain)

; Make a request
Global $hRequest = _WinHttpOpenRequest($hConnect, "GET", $sPage)

_WinHttpSetOption($hRequest, $WINHTTP_OPTION_DECOMPRESSION, $WINHTTP_DECOMPRESSION_FLAG_ALL)
_WinHttpSetOption($hRequest, $WINHTTP_OPTION_UNSAFE_HEADER_PARSING, 1)
_WinHttpSetOption($hRequest, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS)
_WinHttpSetOption(_WinHttpQueryOption(_WinHttpQueryOption($hRequest, $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_SECURE_PROTOCOLS, BitOR($WINHTTP_FLAG_SECURE_PROTOCOL_ALL, $WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1, $WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2))

; Send it. Specify additional data to send too. This is required by the Google API:
_WinHttpSendRequest($hRequest)
If @error Then ConsoleWrite("_WinHttpSendRequest _WinAPI_GetLastError=" & _WinAPI_GetLastError() & @CRLF)

; Wait for the response
_WinHttpReceiveResponse($hRequest)
If @error Then ConsoleWrite("_WinHttpReceiveResponse _WinAPI_GetLastError=" & _WinAPI_GetLastError() & @CRLF)

; See what's returned
Dim $sReturned
If _WinHttpQueryDataAvailable($hRequest) Then ; if there is data
    Do
        $sReturned &= _WinHttpReadData($hRequest)
    Until @error
EndIf

; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; See what's returned
ConsoleWrite($sReturned & @CRLF)
MsgBox(64 + 262144, "Done", "Page source is printed to console")

This fails for me under Windows Server 2016, with this error --

_WinHttpReceiveResponse _WinAPI_GetLastError=12175

It works if I comment out the final _WinHttpSetOption line.

Link to comment
Share on other sites

Thanks Danp2 for the effort.  It is still failing with or without the last _WinHttpSetOption.  But it is not that important after all.  The whole UDF is working fine, just that lousy site refuses to respond.

Link to comment
Share on other sites

@Danp2 is there a way in webdriver to see if 'a click on a button' happened?  

I tried this but it didn't work.

Local $hDLL = DllOpen("user32.dll")

; Click 'OK'
$wOK = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='me36627dd-pb']")
Do
    _WD_ElementAction($sSession, $wOK, 'click')
    Sleep(1750)
    ConsoleWrite(@CRLF & @CRLF & "$wOK: " & $wOK & " at line: " & @ScriptLineNumber & @CRLF & @CRLF )
Until _IsPressed("01", $hDLL) = "True" ;_WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='me36627dd-pb']") = ""

I need to know if this button was actually clicked or not. Sometimes the code runs but the click doesn't happen. (this is rare but annoying when it does happen)

Link to comment
Share on other sites

Hi,

I'm new on this forum and since updating the WebDriver from 0.1.0.20 to 0.3.0.4 my code doesn't work anymore.

I'm using Firefox 79.0

My (simplified) code:

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

Local $sDesiredCapabilities
Local $sSession

$_WD_DEBUG = True

SetupGecko()
_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.google.com")

Sleep(1000)
ExitProg()

Func ExitProg()
    _WD_DeleteSession($sSession)
    _WD_Shutdown()
EndFunc

Func SetupGecko()

    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('DriverParams', '--log trace')
    _WD_Option('Port', 4444)

    $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'

EndFunc

The output I'm getting:

_WD_IsLatestRelease: True
_WDStartup: OS: WIN_10 WIN32_NT 18362 
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.3.0.4 (Up to date)
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver: geckodriver.exe
_WDStartup: Params: --log trace
_WDStartup: Port:   4444
__WD_Post: URL=HTTP://127.0.0.1:4444/session; $sData={"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}
__WD_Post: StatusCode=500; ResponseText={"value":{"error":"unknown error","message":"Invalid Content-Type","stacktrace":""}}...
_WD_CreateSession: {"value":{"error":"unknown error","message":"Invalid Content-Type","stacktrace":""}}
_WD_CreateSession ==> Webdriver Exception: Invalid Content-Type
__WD_Post: URL=HTTP://127.0.0.1:4444/session//url; $sData={"url":"https://www.google.com"}
__WD_Post: StatusCode=405; ResponseText=HTTP method not allowed...
_WD_Navigate: HTTP method not allowed
__WD_Delete: URL=HTTP://127.0.0.1:4444/session/
__WD_Delete: StatusCode=405; ResponseText=HTTP method not allowed...
_WD_DeleteSession: HTTP method not allowed

I'm not even managing to get Firefox to open.

Please help.

Link to comment
Share on other sites

@_Ace_ The desiredCapabilities formatting changed a while back. It's possible that they dropped support for the older format in the newer geckodriver. Can you try it with this instead, which is what you will find in wd_demo?

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}'

Edit: Nevermind... I checked and I'm seeing the same thing. 🤔

Edited by Danp2
Link to comment
Share on other sites

@Danp2 Hello, I am having a problem with opening firefox. But chrome is fine with me. Here is my test code

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


Local $sDesiredCapabilities

Call(SetupGecko)
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "http://youtube.com")
$Element_video_title =  _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,'//*[@id="video-title"]')
_WD_ElementAction($sSession, $Element_video_title, 'click')

Func SetupGecko()
_WD_Option('Driver', 'geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}'
EndFunc

And here is my log :

_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.5 (Up to date)
_WDStartup: WinHTTP:    1.6.4.1 (Download latest source at <https://raw.githubusercontent.com/dragana-r/autoit-winhttp/master/WinHttp.au3>)
_WDStartup: Driver: geckodriver.exe
_WDStartup: Params: --log trace
_WDStartup: Port:   4444
__WD_Post: URL=HTTP://127.0.0.1:4444/session; $sData={"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}
__WD_Post: StatusCode=500; ResponseText={"value":{"error":"session not created","message":"Unable to find a matching set of capabilities","s...
_WD_CreateSession: {"value":{"error":"session not created","message":"Unable to find a matching set of capabilities","stacktrace":""}}
_WD_CreateSession ==> Webdriver Exception: Unable to find a matching set of capabilities
__WD_Post: URL=HTTP://127.0.0.1:4444/session//url; $sData={"url":"http://youtube.com"}
__WD_Post: StatusCode=405; ResponseText=HTTP method not allowed...
_WD_Navigate: HTTP method not allowed
__WD_Post: URL=HTTP://127.0.0.1:4444/session//element; $sData={"using":"xpath","value":"//*[@id=\"video-title\"]"}
__WD_Post: StatusCode=405; ResponseText=HTTP method not allowed...
_WD_FindElement: HTTP method not allowed
_WD_FindElement ==> Webdriver Exception: HTTP status = 405
__WD_Post: URL=HTTP://127.0.0.1:4444/session//element//click; $sData={"id":""}
__WD_Post: StatusCode=405; ResponseText=HTTP method not allowed...
_WD_ElementAction: HTTP method not allowed...
_WD_ElementAction ==> Webdriver Exception: HTTP method not allowed

Tried it with chrome is ok. But when I tried firefox, only firefox 56 was running but not firefox 79 (I installed 2 firefox version). I deleted all of them and install the newest firefox which is 79ver but got that error.

Link to comment
Share on other sites

@ThePoro A couple of things -

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

1. Follow the above link or see here about getting an update to WinHTTP

Quote
_WD_CreateSession ==> Webdriver Exception: Unable to find a matching set of capabilities

2. I ran into a similar situation recently when running geckodriver 0.27. I'm guessing that you are running a 64bit version of Windows. Try running the x64 version of geckodriver.

 

Link to comment
Share on other sites

7 hours ago, Danp2 said:

@ThePoro A couple of things -

1. Follow the above link or see here about getting an update to WinHTTP

2. I ran into a similar situation recently when running geckodriver 0.27. I'm guessing that you are running a 64bit version of Windows. Try running the x64 version of geckodriver.

 

Pefect, it is fine now. Thanks for your work and your help.

Link to comment
Share on other sites

Hey,

I have tried to log in myself to chrome or gmail. But it does not working. I used the example from @Danp2

But after the adress has been entered, it does not continue. When I click the "Next" Button myself, a message pop up "Login not possible" The browser is not safe.

Thanks for your help.

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

Local $sDesiredCapabilities, $sSession, $sElement
Local $sEmailAddress = 'yourname@gmail.com'
Local $sPassword = 'yourpassword'

SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.gmail.com")

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='identifierId']")
_WD_ElementAction($sSession, $sElement, 'value', $sEmailAddress)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@class='RveJvd snByac']")
_WD_ElementAction($sSession, $sElement, 'click')
_WD_LoadWait($sSession, 1000)


$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='password']")
_WD_ElementAction($sSession, $sElement, 'value', $sPassword)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='passwordNext']")
_WD_ElementAction($sSession, $sElement, 'click')
_WD_LoadWait($sSession)

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

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}'
EndFunc

 

 

Link to comment
Share on other sites

5 hours ago, Chris2 said:

But after the adress has been entered, it does not continue.

Check the Scite console output for errors. FWIW, I find no matching element for this xpath -- //span[@class='RveJvd snByac']

5 hours ago, Chris2 said:

When I click the "Next" Button myself, a message pop up "Login not possible"

Lots of people complaining about this same issue online. One known workaround is to use your existing profile instead of allowing chromedriver to create a new one. See the Wiki FAQ for details on how to do this.

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