Jump to content

WebDriver UDF (W3C compliant version) - 2024/09/21


Danp2
 Share

Recommended Posts

Hello,
I need to organize a cycle with the launch of several browsers with different profiles. And if in auto-out it looks like this:
Run ('"C: \Program Files (x86)\Mozilla Firefox\firefox.exe" "--no-remote" -profile "C:\FFProfiles\Bot1" https://test .com/auth/login')

Then through the web driver, I do not know how to do this:
SetupGecko ()
_WD_Startup ()
; $ sSession = _WD_CreateSession ($ sDesiredCapabilities)
; _WD_Navigate ($ sSession, "https://test.com/auth/login/")

Where can I put the profile option to launch several different browsers in a loop?

Link to comment
Share on other sites

try to run the profiles from profie folder, like create  a link to desktop in the settings from the link you can set fix the prifile user and then repeat it with all the profiles you got, add all the profiles to one folder eg in your script folder from there you can run all profiles in a loop im on sth similar, maybe we are on the same project XD

Link to comment
Share on other sites

@sarge There are details in the wiki on how to use an existing user profile with the Webdriver UDF. To make your way work, you need to add the "-marionette" flag and then see this post on how to attach to an existing instance of Firefox.

Haven't tried doing this where multiple profiles are involved, so YMMV.

Link to comment
Share on other sites

40 minutes ago, svenjatzu said:

попробуйте запустить профили из папки profie, например, создать ссылку на рабочий стол в настройках по ссылке, которую вы можете установить, исправить пользователя prifile, а затем повторить его со всеми полученными вами профилями, добавить все профили в одну папку, например, в своем скрипте. оттуда вы можете запускать все профили в цикле im на чем-то похожем, возможно мы находимся в одном проекте XD

Do not understand how to do this?
Give an example please..

Link to comment
Share on other sites

  • Developers

Please do not post a translated quote! 
Only quote when needed and in English.   

Thanks jos

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

25 minutes ago, Danp2 said:

@sarge There are details in the wiki on how to use an existing user profile with the Webdriver UDF. To make your way work, you need to add the "-marionette" flag and then see this post on how to attach to an existing instance of Firefox.

Haven't tried doing this where multiple profiles are involved, so YMMV.

Thank you for your answer, but as I understand it, this option "-marionette", only connects to one running browser instance. And if I run them 5, or 50?
How do I specify each of them?

Link to comment
Share on other sites

No, the "-marionette" option can be used to start Firefox with Marionette enabled. This can also be controlled at the profile level.

As I stated before, I haven't had the need to play with multiple profiles, so you may  encounter some unforeseen issues. You'll probably need multiple Geckodriver sessions, so you may need to run multiple scripts, one for each profile in use. That way, each one can utilize a unique set of values for the ports in use by each session.

Link to comment
Share on other sites

Danp2, thank you for your help.

At this moment I have a program:

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

Local $sDesiredCapabilities, $sSession, $sElement
Local $sLogin = 'mylogin'
Local $sPassword = 'mypassword'
SetupGecko()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://test.com/auth/login/")

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='id_username']")
_WD_ElementAction($sSession, $sElement, 'value', $sLogin)

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='id_password']")
_WD_ElementAction($sSession, $sElement, 'value', $sPassword)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@class='button']")
_WD_ElementAction($sSession, $sElement, 'click')
_WD_LoadWait($sSession)

Func SetupGecko()
_WD_Option('Driver', 'geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)
; $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
$sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", "C:/4studio/FFProfiles/Bot1"],"log": {"level": "trace"}}}}}'
EndFunc

If I uncomment the line

$sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions"...

Then I see that the program starts with the desired profile, but is not executed further. That is, the browser does not even follow the link.

In the debug console I see this:

1587329103638   geckodriver     DEBUG   Listening on 127.0.0.1:4444
1587329104121   webdriver::server       DEBUG   -> POST /session {"capabilities"
:{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", "C:/4studio/FFProf
iles/Bot1"],"log": {"level": "trace"}}}}}
1587329104121   mozrunner::runner       INFO    Running command: "C:\\Program Fi
les (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:/4studio/FF
Profiles/Bot1" "-foreground" "-no-remote"
1587329104121   geckodriver::marionette DEBUG   Waiting 60s to connect to browse
r on 127.0.0.1:52513
1587329164964   mozrunner::runner       DEBUG   Killing process 4084
1587329164964   webdriver::server       DEBUG   <- 500 Internal Server Error {"v
alue":{"error":"timeout","message":"connection refused","stacktrace":""}}

If I uncomment the line: 

; $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true ...

That authorization passes, but the browser starts with the default profile.
Please tell me, is it possible to make the program work with the right profile?

 

Link to comment
Share on other sites

@sarge From your debug log, it appears to be wanting to connect on port 52513. Check the marionette.port setting for the profile in question and make sure it matches. If not, then you may need to provide the correct port number to geckodriver.exe.

From a command prompt, issue the command "geckodriver --help" to see the available options, which you would need to add to your existing '_WD_Option('DriverParams' line.

Link to comment
Share on other sites

On 4/20/2020 at 1:25 AM, Danp2 said:

@sarge From your debug log, it appears to be wanting to connect on port 52513. Check the marionette.port setting for the profile in question and make sure it matches. If not, then you may need to provide the correct port number to geckodriver.exe.

From a command prompt, issue the command "geckodriver --help" to see the available options, which you would need to add to your existing '_WD_Option('DriverParams' line. 

Hello,
Unfortunately this does not work.
firefox uses the port 2828 for the marionette by default.
And I read the "geckodriver --help" put an additional option:

_WD_Option('marionette-port', 2828)

Without result, an arbitrary port is selected in the console:

geckodriver::marionette DEBUG   Waiting 60s to connect to browse
r on 127.0.0.1:49315

It can be fixed?

 

 

Link to comment
Share on other sites

10 minutes ago, sarge said:

_WD_Option('marionette-port', 2828)

That would return an error, since 'marionette-port' isn't a recognized option. Instead, you would want to do something like this --

_WD_Option('DriverParams', '--marionette-port 2828')

This value will then be passed as a parameter to the designated webdriver when you call _WD_Startup.

Link to comment
Share on other sites

Danp2, thank you for your help!

Everything worked, the browser starts, and navigate.
But I just can’t run multiple browsers in a loop.
That is, I can’t insert a variable in the gecko driver options:

For $i = 1 to 5 Step 1
                $p = 2828 + $i
                $b = 'C:/4studio/FFProfiles/Bot'&$i
                _WD_Option('Driver', 'geckodriver.exe')
                _WD_Option('DriverParams', '--log trace')
                _WD_Option('DriverParams', '--marionette-port $p')
                $sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", $b"],"log": {"level": "trace"}}}}}'
                _WD_Startup()
                $sSession = _WD_CreateSession($sDesiredCapabilities)
                _WD_Navigate($sSession, "https://2ip.ru")
              Next

Parameter Values in rows: '--marionette-port $p' and ["-profile", $b"] are not converted to values 😞

Maybe I'm writing them wrong?

And one more question.
Is it possible to program random browser behavior?
That is, clicks on a random place in the window?

Link to comment
Share on other sites

25 minutes ago, sarge said:

Maybe I'm writing them wrong?

Yep... here's the correct way --

_WD_Option('DriverParams', '--marionette-port ' & $p)
26 minutes ago, sarge said:

Is it possible to program random browser behavior?
That is, clicks on a random place in the window?

I don't see why this wouldn't be possible. Perhaps you could explain your scenario where this is needed?

Link to comment
Share on other sites

Thank you, option:

_WD_Option('DriverParams', '--marionette-port ' & $p)

- worked!

But:

$sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", & $b],"log": {"level": "trace"}}}}}'

Not worked 😞

Regarding the random behavior of the bot, I need the bot to randomly switch to another window on the page when the planned presence in the window we need is over. Imitating a person who is on a site with a *snip (let's not discuss that here)*  for example. Enabling this behavior of the browser (bot) must be done either through the scheduler or by command.
I wish the bot could even donate randomly, but this is probably impossible ...

 

Edited by Jos
Link to comment
Share on other sites

Unfortunately, it does not work 😞

$sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", "& $b"],"log": {"level": "trace"}}}}}'

I tried different options, but failed.. Parameter $b are not converted to values 😞


Regarding the behavior of the bot, I apologize for the incorrect question.

Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2024/09/21
  • Melba23 pinned this topic

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

×
×
  • Create New...