Jump to content

Webdriver + Firefox opening existing sessions


 Share

Recommended Posts

Hello,
I got a problem connecting to open sessions with geckogriver:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Schedule
            For $i = 1 to 2 Step 1
                $p = 2827 + $i
                $b = 'C:/4test/FFProfiles/Bot'&$i
                SGLoop()
                _WD_Startup()
                $sSession = _WD_CreateSession($sDesiredCapabilities)
                _WD_Navigate($sSession, "https://2ip.ru")
            Next
        Case $Now
            For $i = 1 to 2 Step 1
                $p = 2827 + $i
                $b = 'C:/4test/FFProfiles/Bot'&$i
                urlins()
            Next
    EndSwitch
WEnd

Func urlins()
    SGLoop()
    _WD_Startup()
    $sSession = _WD_CreateSession($sDesiredCapabilities)
    _WD_Navigate($sSession, "https://test.com/login/")
EndFunc
Func SGLoop()
    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('Port', 4444)
    _WD_Option('DriverParams', '--log trace --marionette-port ' & $p)
    $sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", "' &$b&'"],"log": {"level": "trace"}}}}}'
EndFunc

The first button Case $Schedule, I open the browser window and a link to https: //2ip.ru Everything opens normally.
The second button Case $Now, I try in open sessions to change the link to test.com
And here there is a problem, firefox constantly issues a request to close the browser window. He wants to complete the running process to open a new window!
Although the link in the open windows changes ....

What am I doing wrong?

Edited by sarge
Link to comment
Share on other sites

@ Danp2 OK.

Started to do on chrome.

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Schedule
            For $i = 1 to 2 Step 1
                $p = $mport + $i
                $b = 'C:/4studio/CHProfiles/Bot'&$i
                SGLoop()
                _WD_Startup()
                $sSession = _WD_CreateSession($sDesiredCapabilities)
                _WD_Navigate($sSession, "https://2ip.ru")
            Next

        Case $Now
            For $i = 1 to 2 Step 1
                $p = $mport + $i
                $b = 'C:/4studio/CHProfiles/Bot'&$i
                urlins()
            Next
    EndSwitch
WEnd

Func urlins()
    SGLoop()
    _WD_Navigate($sSession, "https://test.com/login/")
EndFunc

Func SGLoop()
_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":["--user-data-dir='&$b&'", "--proxy-server=192.168.100.127:8080"] } }}}'
EndFunc

The browser starts, links open, but..
Do not tell me why this is constantly popping up in the console?:

Starting ChromeDriver 81.0.4044.69 (6813546031a4bc83f717a2ef7cd4ac6ec1199132-ref
s/branch-heads/4044@{#776}) on port 9515
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent
 access by malicious code.

DevTools listening on ws://127.0.0.1:56353/devtools/browser/1fe7c794-8e36-46f5-a
b46-711df411b4ce
[3100:3668:0430/000112.894:ERROR:browser_switcher_service.cc(238)] XXX Init()

 

Edited by sarge
Link to comment
Share on other sites

  • You can't run multiple instances of Chromedriver all monitoring the same port
  • You don't need multiple instances in this case, since Chromedriver will allow you to create multiple sessions from a single console
  • You need to call _WD_Startup only once, so move that outside of your loop
  • You really should be saving each session id to a separate variable or array so that you can use them later on
  • It no longer makes sense for the function urlins to call SGLoop.

 

Link to comment
Share on other sites

@Danp2 OK.

Here is a short listing of what I need:

#include "wd_core.au3"
#include "wd_helper.au3"
#include <Excel.au3>
#include <Array.au3>

Local $sDesiredCapabilities, $sSession, $sElement
Local $arr[1]

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

For $i = 1 to 2 Step 1
    $b = 'C:/4studio/CHProfiles/Bot'&$i
    SGLoop()
    $sSession = _WD_CreateSession($sDesiredCapabilities)
    _WD_Navigate($sSession, "https://google.com")
    _ArrayAdd($arr, $sSession)
Next

......
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Schedule
            For $i = 1 to 2 Step 1
                $b = 'C:/4studio/CHProfiles/Bot'&$i
                _WD_Navigate($arr[$i], "https://2ip.ru")
            Next
    EndSwitch
WEnd
.......

Func SGLoop()
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--user-data-dir='&$b&'", "--proxy-server=192.168.100.127:8080"] } }}}'
EndFunc

Browsers initially open, but a black terminal window, with the error above, also appears:

Starting ChromeDriver 81.0.4044.69 (6813546031a4bc83f717a2ef7cd4ac6ec1199132-ref
s/branch-heads/4044@{#776}) on port 9515
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent
 access by malicious code.

DevTools listening on ws://127.0.0.1:59521/devtools/browser/1a4f5d55-53ac-4bc8-9
ce4-d000f51c7fd2
[4916:3080:0430/221821.963:ERROR:browser_switcher_service.cc(238)] XXX Init()

DevTools listening on ws://127.0.0.1:59535/devtools/browser/c267b33e-949b-4041-9
b94-45f237503b78
[3352:3172:0430/221823.900:ERROR:browser_switcher_service.cc(238)] XXX Init()

Maybe this is normal?
Navigation by the button(Case $Schedule) in the second cycle, passes fine ...

Or am I misunderstanding something again?

Edited by sarge
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...