Jump to content

Recommended Posts

Posted
  On 5/14/2022 at 5:15 PM, Jemboy said:

Is there a way to assign other icons to the Chromedriver instances or show the fav.ico of the site as an icon for these Chrome web driver instances ?

Expand  

https://www.makeuseof.com/tag/change-taskbar-icons-programs-windows-10/

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 (edited)

I have such DIV

<div class="k-widget k-window displayLayer-basic k-window-maximized" style="padding-top: 27px; min-width: 500px; min-height: 150px; width: 1920px; height: 678px; display: none; top: 0px; left: 0px; touch-action: none; position: fixed;" data-role="draggable">

I need to acompilish 2 task

Task 1:
I need to get all style setting as 2D arrray with 2 coloumns (name, value).

Task 2:
I need to set a value for a specific style setting

 

I know that I can use 

_WD_ElementAction($sSession, $sElement, 'attribute', 'style')

to get current style

 

Question 1:
Is there a way to set up top: 0px; left: 0px; values ?
Only with _WD_ExecuteScript + JavaScript ?

something like:

document.getElementById('lga').style.top = '10px';

or

document.querySelectorAll('....').style.top = '10px';

Question 2:
How to enumerate all used styles settings ?
Should this be done by parsing string for example with RegExp ?
or
Is there a way to use _WD_ExecuteScript + JavaScript ?

Edited by mLipok

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 (edited)

What $sOption  value should be used in case of :
 

_WD_ElementAction($sSession, $sElement, 'css', ????????)

 

Edited by mLipok

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 5/15/2022 at 11:37 AM, mLipok said:

How to enumerate all used styles settings ?

Expand  

As you've identified, there are multiple ways to do this. Here's an alternative using Javascript to return a dictionary object --

;https://stackoverflow.com/questions/32537339/getting-the-values-of-all-the-css-properties-of-a-selected-element-in-selenium
$sScript = 'var items = {};' & _
                'var compsty = getComputedStyle(arguments[0]);' & _
                'var len = compsty.length;' & _
                'for (index = 0; index < len; index++)' & _
                '{items [compsty[index]] = compsty.getPropertyValue(compsty[index])};' & _
                'return items;'

$oStyles = _WD_ExecuteScript($sSession, $sScript, __WD_JsonElement($sElement), Default, $_WD_JSON_Value)
$aKeys  = $oStyles.Keys()
$aItems = $oStyles.Items()

_ArrayDisplay($aKeys)
_ArrayDisplay($aItems)

 

Posted (edited)
  On 5/15/2022 at 12:26 PM, Danp2 said:

Yes... Pretty sure the only way is with _WD_ExecuteScript + JavaScript.

 

Expand  

Something like this:

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_ElementStyleSet
; Description ...: Set style property value for an element
; Syntax ........: _WD_ElementStyleSet($sSession, $sElement, $sPropertyName, $sValue)
; Parameters ....: $sSession - Session ID from _WD_CreateSession
;                  $sElement - Element ID from _WD_FindElement
;                  $sPropertyName - CSS property name which should be set
;                  $sValue - new value of the property
; Return values .: Success - Response from web driver in JSON format
;                  Failure - Response from webdriver and sets @error returned from _WD_ExecuteScript()
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_ElementStyleSet($sSession, $sElement, $sPropertyName, $sValue)
    Lcoal $vResult = _WD_ExecuteScript($sSession, "arguments[0].style." & $sPropertyName & " = '" & $sValue & "'", __WD_JsonElement($sElement), Default, Default)
    Return SetError(@error, @extended, $vResult)
EndFunc   ;==>_WD_ElementStyleSet

?

 

EDIT: maybe function name should be renamed to "_WD_ElementStylePropertySet" or "_WD_ElementSetStyleProperty"

Edited by mLipok
code fixed

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 (edited)
  On 5/15/2022 at 1:51 PM, Danp2 said:

As you've identified, there are multiple ways to do this. Here's an alternative using Javascript to return a dictionary object --

;https://stackoverflow.com/questions/32537339/getting-the-values-of-all-the-css-properties-of-a-selected-element-in-selenium
$sScript = 'var items = {};' & _
                'var compsty = getComputedStyle(arguments[0]);' & _
                'var len = compsty.length;' & _
                'for (index = 0; index < len; index++)' & _
                '{items [compsty[index]] = compsty.getPropertyValue(compsty[index])};' & _
                'return items;'

$oStyles = _WD_ExecuteScript($sSession, $sScript, __WD_JsonElement($sElement), Default, $_WD_JSON_Value)
$aKeys  = $oStyles.Keys()
$aItems = $oStyles.Items()

_ArrayDisplay($aKeys)
_ArrayDisplay($aItems)

 

Expand  

I was trying to modify your script as a combination of:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style

Using this JS:
 

var element = document.getElementById('nav_exercises');
var result ='';
var property ='';
var ComputedStyles = getComputedStyle(element);
for (let i = 0; i < ComputedStyles.length; i++) 
    {
    property = ComputedStyles.item(i);  
    if (element.style.hasOwnProperty(property)) {
        result += property + '|' + ComputedStyles.getPropertyValue(property) + '\n'
    }
}

on
https://www.w3schools.com/

I want to get styles from:

<nav id="nav_exercises" class="w3-hide-small navex" style="position:absolute;background-color:#282A35;color:white;padding-bottom:60px;">

I need to get such results:

  Quote

position|absolute
background-color|#282A35
color|white
padding-bottom|60px

Expand  

but I still get all computed styles.

My point is that I only want to get element own properties.

Any help with fixing my JS snippet ?
 

Edited by mLipok

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 5/15/2022 at 4:58 PM, mLipok said:

_WD_ElementStyleSet

Expand  
  • Does this work correctly with non-string values (ie: boolean or numeric)?
  • You could name it _WD_ElementStyle and support both setting and getting the style values 😉
  Quote

My point is that I only want to get element own properties.

Expand  

In this case, you likely need to manually parse the element's style attribute. There may be a way to do it with Javascript, but I haven't tried it.

Posted
  On 5/15/2022 at 5:53 PM, mLipok said:

Any help with fixing my JS snippet ?

Expand  

Got it fixed with:

var element = document.getElementById('nav_exercises');
var result ='';
var property ='';
var ComputedStyles = getComputedStyle(element);
for (let i = 0; i < element.style.length; i++) 
    {
    property = element.style.item(i)
    result += property + '|' + ComputedStyles.getPropertyValue(property) + '\n'
}

:)

 

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 5/15/2022 at 6:06 PM, Danp2 said:
  • Does this work correctly with non-string values (ie: boolean or numeric)?
Expand  

I'm not sure - not checked yet.

 

  On 5/15/2022 at 6:06 PM, Danp2 said:
  • You could name it _WD_ElementStyle and support both setting and getting the style values
Expand  

take a look on:

https://github.com/Danp2/au3WebDriver/pull/310

 

btw.
I notice that there is no need to use getComputedStyle()

var element = document.getElementById('nav_exercises');
var result ='';
var property ='';
for (let i = 0; i < element.style.length; i++) 
    {
    property = element.style.item(i)
    result += property + ':' + element.style.getPropertyValue(property) + ';'
}

 

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 was wondering if the window handles returned by WebDriver UDF functions like _WD_Window($sSession, 'window') are compatible with the window handles used by standard AutoIt functions like WinGetHandle() or WinWaitActive().

And if they are not compatible, is there an easy method to cast or convert one into the other?

Posted (edited)
  On 5/18/2022 at 2:24 AM, CodeWriter said:

I was wondering if the window handles returned by WebDriver UDF functions like _WD_Window($sSession, 'window') are compatible with the window handles used by standard AutoIt functions like WinGetHandle() or WinWaitActive().

And if they are not compatible, is there an easy method to cast or convert one into the other?

Expand  

_WD_Window() retrives Window handles in this sense:

https://developer.mozilla.org/en-US/docs/Web/API/Window

 

Edited by mLipok

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

If I have nested frames how I can use 
https://developer.mozilla.org/en-US/docs/Web/API/Window/parent

to back to parrent Frame ?

 

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

Could we use WebDriver UDF with "window.Worker"
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers

Is there any sens/usage for this ?

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 5/18/2022 at 11:38 AM, Danp2 said:

Have you tried using_WD_FrameLeave?

Expand  

Thanks will take a look later.

 

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 (edited)

in _WD_FrameLeave there is some checking for browser types

    ;*** Is this something besides a Chrome PASS?
    If $sValue <> Null Then
        ;*** Check for a nested JSON object
        If Json_IsObject($sValue) = True Then
            $asJSON = Json_ObjGetKeys($sValue)

            ;*** Is this an empty nested object
            If UBound($asJSON) = 0 Then ;Firefox PASS
                $sValue = True
            Else ;Chrome and Firefox FAIL
                $sValue = $asJSON[0] & ":" & Json_Get($oJSON, "[value][" & $asJSON[0] & "]")
            EndIf
        EndIf
    Else ;Chrome PASS
        $sValue = True
    EndIf

    Return SetError($_WD_ERROR_Success, 0, $sValue)
EndFunc   ;==>_WD_FrameLeave

its ok but I want to ask about this two comments:

If UBound($asJSON) = 0 Then ;Firefox PASS
        $sValue = True
Else ;Chrome and Firefox FAIL
        $sValue = $asJSON[0] & ":" & Json_Get($oJSON, "[value][" & $asJSON[0] & "]")
EndIf

Why Firefox is mentioned twice in both cases ?
Is it mistake or intentional ?

Edited by mLipok

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 5/18/2022 at 11:12 AM, mLipok said:

_WD_Window() retrives Window handles in this sense:

https://developer.mozilla.org/en-US/docs/Web/API/Window

Expand  

I was refering to:

  On 5/18/2022 at 2:24 AM, CodeWriter said:

if the window handles returned by WebDriver UDF functions like _WD_Window($sSession, 'window') are compatible with the window handles used by standard AutoIt functions like WinGetHandle() or WinWaitActive().

Expand  


So I think that my answer should be extended to:

_WD_Window() retrives Window handles in this sense: https://developer.mozilla.org/en-US/docs/Web/API/Window
So they are not the same as "Window handles" from MSWindowsOS and therefore cannot be used interchangeably.

 

 

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

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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