Jump to content

Recommended Posts

Posted
  On 5/24/2018 at 4:20 PM, grzesiek said:

@horphi

Try this:

_WD_ExecuteScript($sSession, 'document.getElementsByTagName('p')[1].select();')
Expand  

I tried this already...works unfortunately not...:-(

 

_WD_ExecuteScript: {"value":{"error":"javascript error","message":"TypeError: document.getElementsByTagName(...)[1].select 
 --> is not a function","stacktrace":"execute_script @, line 0\ninline javascript, line 1\nsrc: \"undefined\"\nStack:\n

 

Posted

Maybe some minor hint to _WD_NewTab

A error occurs if no browser is opend and the script interrupt.

Func _WD_NewTab($sSession, $lSwitch = True)
    Local Const $sFuncName = "_WD_NewTab"
    Local $sTabHandle = ''

    _WD_ExecuteScript($sSession, 'window.open()', '{}')

    If @error = $_WD_ERROR_Success Then
        Local $aHandles = _WD_Window($sSession, 'handles', '')
        
        $sTabHandle = $aHandles[UBound($aHandles) - 1] ;<<<<<<<<<<<<<<<<<<<<<<If this is no array, script interrupt

        If $lSwitch Then
            _WD_Window($sSession, 'Switch', '{"handle":"' & $sTabHandle & '"}')
        EndIf
    EndIf

    Return SetError($_WD_ERROR_Success, 0, $sTabHandle)
EndFunc


Func _WD_NewTab($sSession, $lSwitch = True)
    Local Const $sFuncName = "_WD_NewTab"
    Local $sTabHandle = ''

    _WD_ExecuteScript($sSession, 'window.open()', '{}')

    If @error = $_WD_ERROR_Success Then
        Local $aHandles = _WD_Window($sSession, 'handles', '')
          If IsArray($aHandles) Then
        $sTabHandle = $aHandles[UBound($aHandles) - 1]
          Else
            ConsoleWrite("> An error occurred. " & 'No Session exist.' & @CRLF)
        EndIf

        If $lSwitch Then
            _WD_Window($sSession, 'Switch', '{"handle":"' & $sTabHandle & '"}')
        EndIf
    EndIf

    Return SetError($_WD_ERROR_Success, 0, $sTabHandle)
EndFunc

 

Posted

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 3 weeks later...
Posted

Hello. Tested with  Microsoft WebDriver (version 16299).

 

Here the Setup Function

Func SetupEdge()
_WD_Option('Driver', 'MicrosoftWebDriver-16299.exe')
_WD_Option('Port', 17556)
EndFunc

_WD_CreateSession need to be modified becuase the sessionid is not returned here [value][sessionId] It's retuned here [sessionId] That's all

I tested just few commands navigate,FindElement,Action But I think all will work correctly.

 

Saludos

 

  • 2 weeks later...
Posted (edited)

the handle do not return from the new tab, because this tab does not have time to create

Fixed _WD_NewTab

Func _WD_NewTab($sSession, $lSwitch = True)
    Local Const $sFuncName = "_WD_NewTab"
    Local $sTabHandle = ''
    Local $TimerNewTab = 0
    _WD_ExecuteScript($sSession, 'window.open()', '{}')
    $TimerNewTab = TimerInit()

    While 1
        If TimerDiff($TimerNewTab) > 5000 Then Return SetError($_WD_ERROR_Success, 0, $sTabHandle)
        If @error = $_WD_ERROR_Success Then
            Local $aHandles = _WD_Window($sSession, 'handles', '')
            $sTabHandle = $aHandles[UBound($aHandles) - 1]
            If $lSwitch Then
                _WD_Window($sSession, 'Switch', '{"handle":"' & $sTabHandle & '"}')
            EndIf
            ExitLoop
        EndIf
        Sleep(10)
    WEnd
    Return SetError($_WD_ERROR_Success, 0, $sTabHandle)
EndFunc   ;==>_WD_NewTab

Now, if the tab is not created within 5 seconds, it returns an SetError

Edited by alexmerfi
Posted
  On 6/29/2018 at 4:28 AM, alexmerfi said:

the handle do not return from the new tab, because this tab does not have time to create

Expand  

Thanks for the feedback. Can you provide further details so that I can replicate the issue? Which browser, etc.

Also, I can see a few issues with this revised implementation, such as --

  • Possible misplaced If @error check.
  • Wrong return value when timeout occurs
  • How do you determine that the new tab exists?

Finally, I would suggest making the timer "max" value an optional parameter.

P.S. Perhaps an even simpler implementation would be to replace the timer loop with a single Sleep command using the same optional variable to allow the calling routine to determine the desired delay length.

Posted
  On 6/29/2018 at 12:06 PM, Danp2 said:

Thanks for the feedback. Can you provide further details so that I can replicate the issue? Which browser, etc.

Expand  

Firefox 61.0 64 bit, Hyperv Windows 10 x32

Autoit 3.3.14.2

#include "wd_core.au3"
#include "wd_helper.au3"
Global $sSession
Global $sDesiredCapabilities

$_WD_DEBUG = False

SetupGecko()
_WD_Startup()


$sSession = _WD_CreateSession($sDesiredCapabilities)

$HandleTab = _WD_NewTab($sSession, True)
MsgBox(0, "", $HandleTab)


_WD_DeleteSession($sSession)
_WD_Shutdown()
Exit



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   ;==>SetupGecko


 

Posted
  On 6/29/2018 at 12:06 PM, Danp2 said:

Possible misplaced If @error check.

Expand  

Yes, you're right, I have not yet found how to fix this inside this function. Perhaps, if the _WD_ExecuteScript will store errors in the global variable, and I will check it through

While 1

if $GlobalVariableOfErrorExecuteScript='okay'  then exitloop

wend

 

Posted
  On 6/29/2018 at 12:06 PM, Danp2 said:

P.S. Perhaps an even simpler implementation would be to replace the timer loop with a single Sleep command using the same optional variable to allow the calling routine to determine the desired delay length.

Expand  

Yes, this is a simple implementation. But, for example, if you have a heavily loaded virtual machine and the fiefox tab will be created for a very long time, it will not always work sleep. Of course SLEEP can be done for 5 minutes :) but in some tasks some people can lose a lot of money.

 

Posted
  On 7/1/2018 at 7:12 PM, alexmerfi said:

Firefox 61.0 64 bit, Hyperv Windows 10 x32

Autoit 3.3.14.2

Expand  

Does it fail for you every time in this environment? If so, please change $_WD_DEBUG = True and post the contents of the Scite output window after running your code.

Also, is there a reason you aren't running the latest version of Autoit?

  On 7/1/2018 at 7:14 PM, alexmerfi said:
If $HandleTab<>'' then MsgBox(0,"","Table IS EXIST, because it return value of handle")
 _WD_Window($sSession, 'Switch', '{"handle":"' & $HandleTab & '"}')
EndIf
Expand  

But the current implementation should return the handle of the last tab (even if the newest one hasn't appeared as you previously indicated). So $HandleTab would only be blank if there was an error from _WD_ExecuteScript.

 

  On 7/1/2018 at 7:17 PM, alexmerfi said:

Why Wrong? 

if i change timeout 5000 to 0

If TimerDiff($TimerNewTab) > 0 Then Return SetError($_WD_ERROR_Success, 0, $sTabHandle)

i return $HandleTab='' (nothing)

Expand  

Actually, I meant the error code, not the return value. I would use $_WD_ERROR_Timeout here instead of $_WD_ERROR_Success

  On 7/1/2018 at 7:28 PM, alexmerfi said:

Yes, you're right, I have not yet found how to fix this inside this function. Perhaps, if the _WD_ExecuteScript will store errors in the global variable, and I will check it through

Expand  

Shouldn't be necessary to use a global here. Look at other instance where the value of @error is saved to $iErr.

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
×
×
  • Create New...