Jump to content

Is WebDriver UDF always reliable?


Go to solution Solved by SEKOMD,

Recommended Posts

Could you please tell me, is this a global issue, does WebDriver UDF generally work reliably? Are there any occasional "wandering glitches"? I have a script that sometimes works perfectly, and other times doesn't work at all.

I just can't grasp it - is WebDriver a stable library or can there be intermittent glitches?

Link to comment
Share on other sites

I understand that without code, there isn't much point, I will try to provide it a bit later.

But yes. I have started a While loop and notice that around the 20-30th iteration, WebDriver stops functioning correctly.

Moreover, the chrome.exe process does not persist, so the issue lies there (the launched process remains).

Link to comment
Share on other sites

Posted (edited)
MsgBox(64,'','We will load the service page.')
        _WD_CapabilitiesAdd('args', '--app=https://0.0.0.0')
        _WD_SetTimeouts($sSession, '{"pageLoad":2000}')
        _WD_LoadWait($sSession)
        _WD_Navigate($sSession, 'chrome://version/') ;service page (to get the window to display at all)
        _WD_LoadWait($sSession)
        MsgBox(64,'','Has the test page loaded??')

In this particular segment, an error occurs once every five successful runs. Any ideas on what this might be related to?

Edited by SEKOMD
Link to comment
Share on other sites

  • Solution
Posted (edited)
Func _WD_ChromeStart($sURL, $sProfile, $sPort, $sBinary)

    Local $_WD_GetFreePort = _WD_GetFreePort()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', $_WD_GetFreePort)
    FileDelete(@ScriptDir & '\_WD_ChromeStart.log')
    _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\_WD_ChromeStart.log" --port=' & $_WD_GetFreePort)

    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome')
    _WD_CapabilitiesAdd('firstMatch', 'chrome')
    _WD_CapabilitiesAdd('detach', False)
    _WD_CapabilitiesAdd('browserName', 'chrome')
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('acceptInsecureCerts', True)
    _WD_CapabilitiesAdd('args', '--remote-debugging-port=' & $sPort) 
    _WD_CapabilitiesAdd('args', '--user-data-dir=' & $sProfile)
    _WD_CapabilitiesAdd('binary', $sBinary)
    _WD_CapabilitiesAdd('args', '--app=https://00.00.00.00')

    Local $sCapabilities = _WD_CapabilitiesGet()
    _WD_Startup()
    Local $sSession = _WD_CreateSession($sCapabilities)

    ;============================================================================
    Local $hSessionWindow, $iIDSession = (Random(999999, 999999999, 1) + Random(999999, 999999999, 1) + @MSEC) * @SEC

    While 1
        ;Sleep(100)
        ;== ! PROBLEM ! ==
        While 1
            MsgBox(64, '', 'Step 1')
            _WD_SetTimeouts($sSession, '{"pageLoad":2000}')
            _WD_LoadWait($sSession, 100, 9999)
            _WD_Navigate($sSession, 'chrome://version/') 
            _WD_LoadWait($sSession, 100, 9999)
            _WD_ExecuteScript($sSession, 'document.title=' & $iIDSession)
            If MsgBox(64 + 1, '', 'Step 2') = 1 Then ExitLoop
        WEnd
        ;Exit
        ;== ! PROBLEM END !==
        ;Exit
        Local $sTitle
        Do
            $sTitle = _WD_ExecuteScript($sSession, 'return document.title')
            $aTitle = StringSplit($sTitle, '":"', 1)[2]
            $sTitle = StringSplit($aTitle, '"}', 1)[1]
        Until StringInStr($sTitle, $iIDSession)
        While 1
            Local $aList = WinList()
            For $i = 1 To $aList[0][0]
                If $aList[$i][0] <> '' Then
                    ConsoleWrite('_WD_ChromeStart: $aList[$i][0]=' & $aList[$i][0] & ' / ' & '$iIDSession=' & $iIDSession & @CRLF)
                    If StringInStr($aList[$i][0], $iIDSession) Then
                        $hSessionWindow = $aList[$i][1] 
                        ExitLoop 3
                    EndIf
                EndIf
            Next
        WEnd
    WEnd
    ;====================================================

    _WD_Navigate($sSession, $sURL)
    _WD_LoadWait($sSession, 100, 9999)
    _WD_LoadWait($sSession)
    ;_WD_DeleteSession($sSession)
    _WD_Shutdown()

    Return $hSessionWindow
EndFunc   ;==>_WD_ChromeStart

Here is the function, for unclear reasons, it sometimes works and sometimes doesn't. What could be the issue? The problematic section is == ! PROBLEM ! ==

 

The issue has been resolved. It was all about _WD_SetTimeouts($sSession, '{"pageLoad":2000}'). 
I hope this will be helpful to someone!

Edited by SEKOMD
Link to comment
Share on other sites

 

Could you please advise on which parameter needs to be added to make the --app mode work? (opening a website as an application)

 

_WD_CapabilitiesStartup()
    $r = Random(1, 999, 1)
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome' & $r)
    _WD_CapabilitiesAdd('firstMatch', 'chrome' & $r)
    _WD_CapabilitiesAdd('browserName', 'chrome' & $r)
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
    _WD_CapabilitiesAdd('unhandledPromptBehavior', 'ignore')
    _WD_CapabilitiesAdd('acceptInsecureCerts', True)
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('detach', False)

    _WD_CapabilitiesAdd('args', '--user-data-dir=' & $sProfile)
    _WD_CapabilitiesAdd('binary', $sBinary)
    _WD_CapabilitiesAdd('args', '--force-renderer-accessibility')
    _WD_CapabilitiesAdd('args', '--remote-debugging-port=' & $sPort)
    _WD_CapabilitiesAdd('args', '--app=https://00.00.00.00')

 

Link to comment
Share on other sites

6 minutes ago, Danp2 said:

Привет,

Описание проблемы и ее решения расплывчатое. Что происходит, когда "совсем не работает"? Можете показать вывод в консоли Scite с ошибками?

Вы удалили вызов _WD_SetTimeouts или было какое-то другое решение?

С уважением,

Дэн

However, the issue is not about that. The problem is that I just can't seem to launch two Chrome windows. I want them both to work in app mode, like applications.

Moderators! Please delete this topic, as it's really confusing here.

Link to comment
Share on other sites

Posted (edited)


I just can't seem to launch two Chrome windows in app mode. I need to be able to control each one. I can launch two windows in app mode simultaneously, but that's not what I need.

Here's an example of what I'm trying to do:

 

#include 'wd_core.au3'
#include 'wd_capabilities.au3'
#include 'wd_helper.au3'


;$sURL = 'https://google.com'
;$sProfile = 'D:\MyTextarea\CHROME_MUSIC\PROFILE'
;$sBinary = 'D:\MyTextarea\CHROME_MUSIC\BINARY\chrome.exe'


$_WD_GetFreePort = _WD_GetFreePort()
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', $_WD_GetFreePort)
FileDelete(@ScriptDir & '\_WD_ChromeStart.log')
_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\_WD_ChromeStart.log" --port=' & $_WD_GetFreePort)

_WD_CapabilitiesStartup()

_WD_CapabilitiesStartup()
_WD_CapabilitiesAdd('alwaysMatch', 'chrome')
_WD_CapabilitiesAdd('firstMatch', 'chrome')
_WD_CapabilitiesAdd('browserName', 'chrome')
_WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
_WD_CapabilitiesAdd('acceptInsecureCerts', True)
_WD_CapabilitiesAdd('w3c', True)
_WD_CapabilitiesAdd('detach', False)
;_WD_CapabilitiesAdd('args', '--user-data-dir=' & $sProfile)
;_WD_CapabilitiesAdd('binary', $sBinary)
_WD_CapabilitiesAdd('args', '--force-renderer-accessibility')
_WD_CapabilitiesAdd('args', '--remote-debugging-port=9222')
;_WD_CapabilitiesAdd('debuggerAddress', '127.0.0.1:9222')
_WD_CapabilitiesAdd('args', '--app=https://0.0.0.0')

_WD_Startup()

$_WD_CapabilitiesGet = _WD_CapabilitiesGet()

$sSession1 = _WD_CreateSession($_WD_CapabilitiesGet)
$sSession2 = _WD_CreateSession($_WD_CapabilitiesGet)

_WD_Navigate($sSession1,  'https://google.com') ;not working
_WD_Navigate($sSession2,  'https://bing.com') ;not working

_WD_Shutdown($sSession1)
_WD_Shutdown($sSession2)

 

Edited by SEKOMD
Link to comment
Share on other sites

1 minute ago, Andreik said:

It's the third tread asking basically the same question about WebDriver. It's Sunday, wait some time and give people a chance to reply to your question.

I am terribly sorry, it happened accidentally. Usually I search for solutions on my own and for a very long time, but this time I am powerless.

Link to comment
Share on other sites

There's no need to quote me in your response, but please use English if you insist on doing it as this is an English language forum. It seems like your other thread is related to this one, so maybe you should request the moderators to combine them.

FWIW, launching two separate browser windows isn't difficult using Webdriver, so I suspect that there is something you haven't explained fully about your particular requirements.

Link to comment
Share on other sites

$sAttach1 = _WD_Attach($sSession2,'https://0.0.0.0','url') ;not working
$sAttach2 = _WD_Attach($sSession2,'https://0.0.0.0','url') ;not working
_WD_Navigate($sAttach2, 'https://bing.com')
_WD_Navigate($sAttach1,  'https://google.com')

Unfortunately, this also does not work.

Link to comment
Share on other sites

Posted (edited)
36 minutes ago, Danp2 said:

As I mentioned elsewhere, "not working" isn't a sufficient description of the problem. After a brief look at your code, I suspect that some of your problems arise because you are trying to use the same user profile in two different sessions.

You were right. Yes, indeed, if different profiles - you can open two windows in app mode.

BUT there is another way to do it:

1. Open a window with the command _WD_CapabilitiesAdd('args', '--remote-debugging-port=9223')
2. Then connect to that window with the command _WD_CapabilitiesAdd('debuggerAddress', '127.0.0.1:9223')
This also works! In the end, I managed to find two ways! :)

 

#include 'wd_core.au3'
#include 'wd_capabilities.au3'
#include 'wd_helper.au3'


$_WD_GetFreePort = _WD_GetFreePort()
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', $_WD_GetFreePort)
FileDelete(@ScriptDir & '\_WD_ChromeStart.log')
_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\_WD_ChromeStart.log" --port=' & $_WD_GetFreePort)

_WD_CapabilitiesStartup()

_WD_CapabilitiesStartup()
_WD_CapabilitiesAdd('alwaysMatch', 'chrome')
_WD_CapabilitiesAdd('firstMatch', 'chrome')
_WD_CapabilitiesAdd('browserName', 'chrome')
_WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
_WD_CapabilitiesAdd('acceptInsecureCerts', True)
_WD_CapabilitiesAdd('w3c', True)
_WD_CapabilitiesAdd('detach', False)
_WD_CapabilitiesAdd('args', '--user-data-dir=D:\MyTextarea\CHROME_MUSIC\PROFILE')
_WD_CapabilitiesAdd('binary', 'D:\MyTextarea\CHROME_MUSIC\BINARY\chrome.exe')
_WD_CapabilitiesAdd('args', '--force-renderer-accessibility')
_WD_CapabilitiesAdd('args', '--remote-debugging-port=9223') ; <<< IMPORTANT <<<
;_WD_CapabilitiesAdd('debuggerAddress', '127.0.0.1:9223') ; <<< IMPORTANT <<<
_WD_CapabilitiesAdd('args', '--app=https://0.0.0.0')

_WD_Startup()

$_WD_CapabilitiesGet = _WD_CapabilitiesGet()

$sSession1 = _WD_CreateSession($_WD_CapabilitiesGet)

_WD_Navigate($sSession1,  'https://bing.com') ; <<< when using the debuggerAddress command, you simply change the address, for example to https://bing.com

Please write down any comments or nuances.

Edited by SEKOMD
Link to comment
Share on other sites

Posted (edited)
5 hours ago, SEKOMD said:

1. Open a window with the command _WD_CapabilitiesAdd('args', '--remote-debugging-port=9223')
2. Then connect to that window with the command _WD_CapabilitiesAdd('debuggerAddress', '127.0.0.1:9223')

This method is not working:

 

#include 'wd_core.au3'
#include 'wd_capabilities.au3'
#include 'wd_helper.au3'

_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 64000)
If FileExists(@ScriptDir & '\_WD_ChromeStart.log') Then FileDelete(@ScriptDir & '\_WD_ChromeStart.log')
_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\_WD_ChromeStart.log" --port=' & 64000)
_ChromeCapabilitiesSetup('E:\MyTextareaNew\Chrome\Profile', 9222, False)
;_ChromeCapabilitiesSetup('E:\MyTextareaNew\Chrome\Profile', 9211, False)

;_ChromeCapabilitiesSetup('E:\MyTextareaNew\Chrome\Profile', 9222, True)
;_ChromeCapabilitiesSetup('E:\MyTextareaNew\Chrome\Profile', 9211, True)
_WD_Startup()

Local $sCapabilities = _WD_CapabilitiesGet()
Local $sSession = _WD_CreateSession($sCapabilities)

_WD_SetTimeouts($sSession, '{"pageLoad":20000}')
_WD_Navigate($sSession, 'https://bing.com')
_WD_LoadWait($sSession, 50, 2000)
_WD_Shutdown($sSession)

 

It doesn’t work correctly - three windows cannot be opened::

 

#include 'wd_core.au3'
#include 'wd_capabilities.au3'
#include 'wd_helper.au3'

;working method
_Example('E:\MyTextareaNew\Chrome\Profile', 'https://google.com')
_Example('E:\MyTextareaNew\Chrome\Profile2', 'https://bing.com')
_Example('E:\MyTextareaNew\Chrome\Profile2', 'https://msn.com')

Func _Example($sProfile, $sURL)
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 64000)
    If FileExists(@ScriptDir & '\_WD_ChromeStart.log') Then FileDelete(@ScriptDir & '\_WD_ChromeStart.log')
    _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\_WD_ChromeStart.log" --port=' & 64000)
    _ChromeCapabilitiesSetup($sProfile, 9222, False)
    _WD_Startup()

    Local $sCapabilities = _WD_CapabilitiesGet()
    Local $sSession = _WD_CreateSession($sCapabilities)

    _WD_SetTimeouts($sSession, '{"pageLoad":20000}')
    _WD_Navigate($sSession, $sURL)
    _WD_LoadWait($sSession, 50, 2000)
    _WD_Shutdown($sSession) ;??? don't working
EndFunc   ;==>_Example

Func _ChromeCapabilitiesSetup($sProfile, $iPort, $bAttach = False)
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome')
    _WD_CapabilitiesAdd('firstMatch', 'chrome')
    _WD_CapabilitiesAdd('browserName', 'chrome')
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
    _WD_CapabilitiesAdd('acceptInsecureCerts', True)
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('detach', False)
    _WD_CapabilitiesAdd('args', '--user-data-dir=D:\MyTextarea\CHROME_MUSIC\PROFILE')
    _WD_CapabilitiesAdd('binary', 'D:\MyTextarea\CHROME_MUSIC\BINARY\chrome.exe')
    _WD_CapabilitiesAdd('args', '--force-renderer-accessibility')
    If $bAttach Then
        _WD_CapabilitiesAdd('debuggerAddress', '127.0.0.1:' & $iPort)
    Else
        _WD_CapabilitiesAdd('args', '--remote-debugging-port=' & $iPort)
    EndIf
    _WD_CapabilitiesAdd('args', '--app=http://0.0.0.0')
EndFunc   ;==>_ChromeCapabilitiesSetup


Sorry for my English.

I will be glad to see your comments.

This task is probably impossible for me. Help me please.

Edited by SEKOMD
Link to comment
Share on other sites

  • Developers

All 3 topics merged into this one! Please stick with one topic the next time when asking question about the same thing!

Thanks

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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