Jump to content

Recommended Posts

Posted

For the past two days I've been reading all Wiki pages, installed all the demos etc. but I am still unable to do this simple workflow

1. I want to use WebDriver UDF to open Chrome (Set chrome option arguments - Window Size, Pixel ratio, device type and platform name, user-agent.)
2. On new Tab I want to read the tab Title and save it into a TXT file.
3. I need to save the Session ID with my previosly set Capabilities into a file.
4. I want to close the chrome window.

Then

5. I want to open Chrome again, but with my previosly saved Session ID and Capabilities list from the file.
6. And minimaze the window state.
7. After 30 seconds, close the chrome.

I would really appreciate for the WebDriver UDF Helper file, to have also basic code examples, for non coders. For example how to open a windwow etc., save sessions, etc.

Anyway, if someone could help me get started and help me with this workflow, that would be much appreaciated. 😔

Posted

Hi @TTE26,

Welcome to the forum. :welcome:

To improve your chances of getting help, I suggest that you post code showing what you have tried thus far. Also, I would be interested to learn the reasoning behind this workflow, alternatives you've considered, etc.

Regarding items 3 - 5, the Session ID will be invalid after you close the browser, so I don't see how saving it will be beneficial.

Regards,

Dan

P.S. Help file examples may be included in a future release.

 

Posted

Hi! 🤗

I have been grinding for a few days now, have tested and learned a lot.
I've managed to do a lot from my list by myself already.
- The Session ID was accomplished by just using User Profile direcotry argument. 
- I am using SQL functions to save data, so a better solution than just save to text file
- I was able to read Tabs Title using this function
 

_WD_Action($WD_SESSION, 'TITLE')



But I am having a hard time setting the devices Width, Height, PixelRatio, DeviceType, PlatformName.
This is what I have now, and it's not work
 

_WD_CapabilitiesAdd("mobileEmulation", "deviceMetrics", "width=320, height=640, pixelRatio=3" )


How can I fix it? Why is it not working?

Thank you! 🙂

Posted

Yes, I see an error in Webdriver_Testing.log file

[1658890546.183][INFO]: [c566e1ddea7e3b09cbdbd0be1b191500]
RESPONSE InitSession ERROR invalid argument: entry 0 of 'firstMatch' is invalid
from invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: cannot parse mobileEmulation
from invalid argument: 'deviceMetrics' must be a dictionary

On Chromium Site it says:
 

  Quote

Specifying Individual Device Attributes

It is also possible to enable Mobile Emulation by specifying individual attributes. To enable Mobile Emulation this way, the “mobileEmulation” dictionary can contain a “deviceMetrics” dictionary and a “userAgent” string. The following device metrics must be specified in the “deviceMetrics” dictionary:

  • “width” - the width in pixels of the device’s screen

  • “height” - the height in pixels of the device’s screen

  • “pixelRatio” - the device’s pixel ratio

  • "touch" - whether to emulate touch events (defaults to true, usually does not need to be set)

Expand  



So how can I add a deviceMetrics” dictionary the correct way? 
 

 

  On 7/27/2022 at 11:39 AM, Danp2 said:

BTW, what website are you automating with this script?

Expand  


If I get this working, intended to use on my personal sites, to check if they are loading correctly, and take a daily screenshots.


Please let me know how to fix this error.
Any help would be appreciated! 🙃

Posted
  On 7/27/2022 at 2:03 PM, Danp2 said:

Haven't tested it, but this should be more spec compliant than your original version --

_WD_CapabilitiesAdd("mobileEmulation", "deviceMetrics", '"width":320, "height":640, "pixelRatio":3')

 

Expand  

Not working either. Same error. Hmm

Posted

Try this way:

_WD_CapabilitiesAdd("mobileEmulation", "deviceMetrics", '"width":320')
_WD_CapabilitiesAdd("mobileEmulation", "deviceMetrics", '"height":640')
_WD_CapabilitiesAdd("mobileEmulation", "deviceMetrics", '"pixelRatio":3')

 

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

Posted

No no it not works.
Give some time.
I'm digging docs.

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

Posted
  On 7/27/2022 at 1:21 PM, TTE26 said:

the “mobileEmulation” dictionary can contain a “deviceMetrics” dictionary and a “userAgent” string.

Expand  

so at first step:
 

_WD_CapabilitiesAdd("mobileEmulation", "useragent", 'Mozilla/5.0 (Windows NT 10.0; Win' & StringReplace(@OSArch, 'X', '') & '; ' & @CPUArch & ') AppleWebKit/537.36 (KHTML, like Gecko) Chrome/' & _WD_GetBrowserVersion('chrome') & ' Safari/537.36')

 

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

Posted
  On 7/27/2022 at 3:01 PM, mLipok said:

so at first step:
 

_WD_CapabilitiesAdd("mobileEmulation", "useragent", 'Mozilla/5.0 (Windows NT 10.0; Win' & StringReplace(@OSArch, 'X', '') & '; ' & @CPUArch & ') AppleWebKit/537.36 (KHTML, like Gecko) Chrome/' & _WD_GetBrowserVersion('chrome') & ' Safari/537.36')

 

Expand  

Not working, not able to put it together. 🤔


 🤨 However this hard coded JSON works ->
 

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true,  "excludeSwitches": [ "enable-automation"], "args":["user-data-dir=C:\\Users\\R\\AppData\\Local\\Google\\Chrome\\User Data\\"], "mobileEmulation": { "deviceMetrics": { "width": 320, "height": 640, "pixelRatio": 3.0, "click": true}, "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104 Safari/537.36" }}}}}'


But how to create this with _WD_CapabilitiesAdd ?
 

Posted

You can also use:

_WD_CapabilitiesAdd("mobileEmulation", "deviceName", 'Nexus 5')


WIP on deviceMetrics

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

Posted
  On 7/27/2022 at 3:59 PM, mLipok said:

You can also use:

_WD_CapabilitiesAdd("mobileEmulation", "deviceName", 'Nexus 5')


WIP on deviceMetrics

Expand  

Well this works, but not able to set my own resolution and user agents. 
Do you know where can I get a list of supported devices for deviceName?

Posted

https://chromedriver.chromium.org/mobile-emulation

  Quote

Note: ChromeDriver’s list of known devices is generated from those found in the DevTools Emulation panel. However, it is possible to use a version of ChromeDriver against a version of Chrome that has a newer or older list of devices. If you try to use a device name that ChromeDriver doesn’t recognize, you will see an error: “<your device name> must be a valid device.” To emulate a device that ChromeDriver doesn’t know of, enable Mobile Emulation using individual device metrics, as described below.

Expand  

 

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

Posted

I have developed some kind of universal solution, but do not know if @Danp2 will be happy with that ;)


I will send PR to github repo.

 

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

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

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