Jump to content

Recommended Posts

Posted

Question: Is it possible to add something to browser's local storage?

I've recently learned how to add cookie and that was easy, probably adding to local storage is somehow similar?

;cookie add
    $sName = "cookieName"
    $svalue ="cookieValue"
    $sCookie = '{"cookie": {"name":"' & $sName & '","value":"' & $svalue & '"}}'
    $sRes = _WD_Cookies($sSession, 'add', $sCookie)

 

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 07/13/2022
Posted (edited)
  On 7/4/2022 at 12:09 PM, Danp2 said:

IDK. I would expect the saved value to be updated each time the function is called with a new value.

Expand  

What about this scenario:

_MAIN()

Func _Main()
    ; presetting
    $_WD_DEBUG = $_WD_DEBUG_None
    
    _1()
    
    ; restore settings ($_WD_DEBUG_None)
    _WD_DebugSwitch()


    ; set new debug level
    $_WD_DEBUG = $_WD_DEBUG_Error
    ; reset switch internall storage to new setting ($_WD_DEBUG_Error)
    _WD_DebugSwitch(Null)
    
EndFunc

Func _1()
    ; first usage - internally store current settings + switch to $_WD_DEBUG_Full
    _WD_DebugSwitch($_WD_DEBUG_Full)
    ; do your stuff
    _2()
    ; do your stuff
EndFunc

Func _2()
    ; switch to $_WD_DEBUG_Error
    _WD_DebugSwitch($_WD_DEBUG_Error)
    ; do your stuff
EndFunc

This example clearly shows that you need to have direct control over when a stored value is changed.

Here is my modified version:

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_DebugSwitch
; Description ...: Switch to new debug level or switch back to saved debug level
; Syntax ........: _WD_DebugSwitch([$vMode = Default])
; Parameters ....: $vMode               - [optional] Set new $_WD_DEBUG level. When not specified restore saved debug level.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......: Function saves debug level only at first call
; Related .......:
; Link ..........:
; Example .......: _WD_DebugSwitch($_WD_DEBUG_Full)
; ===============================================================================================================================
Func _WD_DebugSwitch($vMode = Default)
    Local Const $sFuncName = "_WD_DebugSwitch"
    Local Static $_WD_DEBUG_Saved = $_WD_DEBUG ; at first run save currently used debug level, and treat them as "DEFAULT USER CHOICE"
    Local $iErr = $_WD_ERROR_Success

    If $vMode = Default Then ; restore saved debug level
        $_WD_DEBUG = $_WD_DEBUG_Saved
    ElseIf $vMode = Null Then ; reset saved debug level
        $_WD_DEBUG_Saved = $_WD_DEBUG
    ElseIf Not IsInt($vMode) Then
        $iErr = $_WD_ERROR_InvalidDataType
    ElseIf $vMode < $_WD_DEBUG_None Or $vMode > $_WD_DEBUG_Full Then
        $iErr = $_WD_ERROR_InvalidValue
    Else ; set new debug level
        $_WD_DEBUG = $vMode
    EndIf
    Return SetError(__WD_Error($sFuncName, $iErr), 0, '')
EndFunc   ;==>_WD_DebugSwitch

It is a combination of two functionalities, the one that I have used so far, and the possibility of changing the saved value (with Null parameter).

 

EDIT:
Moving discussion about _WD_DebugSwitch() to:

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

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 7/18/2022 at 12:07 PM, mLipok said:

What about this scenario:

Expand  

I think this is an overly complex example of poorly written code.😩 IMO, each of your functions that change the logging level should restore it before exiting the function.

  On 7/18/2022 at 12:07 PM, mLipok said:
; set new debug level
    $_WD_DEBUG = $_WD_DEBUG_Error
    ; reset switch internall storage to new setting ($_WD_DEBUG_Error)
    _WD_DebugSwitch(Null)

 

Expand  

This implementation doesn't make sense to me. Why are you manually setting the debug level? Isn't that what _WD_DebugSwitch is supposed to handle?

I'm thinking that you need to consider some alternatives --

  • Use of a stack where you can push / pop debug levels
  • Additional parameters to override default functionality (ie: force update saved debug level)
Posted

Hi Dan,

I have problems in understanding _WD_ElementSelectAction. I want to select an option out of a list but all parameters of _WD_ElementSelectAction seem to retrieve information, not to choose one of the options.

How can I do it?
 

 

Posted (edited)

i would like to ask some help:

i downloaded the chm file from your github map, to see how its working, but i can see only the keywords on left side, nothing deeper content on right side..

how its possible?

that is the greatest way when you planned to know something new where the first step is an invalid..  now lets learn..

this is why i dont want to let away ie.. a once for all working method instead of these forced bugged ...

Edited by vkrisz81
Posted
  On 7/20/2022 at 4:54 PM, Danp2 said:

@vkrisz81You need to unblock the CHM file. See here for explanation.

P.S. This is a common problem with CHM files. It's clear that you are frustrated, but please don't "blame the messenger". 😉

Expand  

of course, i dont blame the creator, i just am angry because i must to start to a new direction and the first step is blocked by this type errors.. this is not against creators or similar, this is against the system.. new new new systems but are not working.. as well

win xp existed.. how many years? was very stable.

win 7 existed how many years? was stable

now win10.. win11.. and bug bug bug :S

and i am forced to follow this because of .. throw it.. thanks i try to fix this

Posted

Hi Dan,

I have problems with the application of _WD_ElementOptionSelect(). Is the following command correct? It's a pulldown menu with different languages to choose from.

$sXPath = "//a[normalize-space()='Sprache']"
$sValue = "German"
_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, $sXPath & "//option[contains '" & $sValue & "'")

 

Posted
  On 7/24/2022 at 6:35 PM, HJL said:

& "'")

Expand  

Issue is here.

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 automated the login of a website (https://login.tecalliance.net) with autoit/webdriver. However while logging into the website there is an checkbox "Remember me" (in Dutch: Mij onthouden"). Checking this checkbox will make the next logon faster, however what ever I do, I cannot get the checkbox to be "checked".

The line starting at: $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@name='remember']")
The "source" below is only one of the version I tried to check the checkbox, but I have been at this for about 2 days Googling and searching the forum.

Does anyone have a suggestion to get this checkbox checked ?

image.png.90c2e73d893f3b4036530ef73cbb80dc.png

image.png.dad5306ff407f00f226ff258f1374839.png

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


$_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error

Local $sDesiredCapabilities, $sSession, $sElement

$lResult = _WD_UpdateDriver('chrome', Default, Default, true )   ;Update Chromedriver
$lErr = @error


SetupChrome()
$ResSU = _WD_Startup()
$ResSUE = @error
If $ResSU=0 then MsgBox (262144,"","Result Startup = " &  $ResSU & "   " & "Error = " & $ResSUE)



$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Window($sSession, 'maximize')
_WD_Navigate($sSession, "https://login.tecalliance.net")
_WD_LoadWait($sSession)

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='cc-btn cc-dismiss']")
$sRes= @error
if $sRes=$_WD_ERROR_Success then
    _WD_ElementAction($sSession, $sElement, 'click')
    _WD_LoadWait($sSession, 1000)
EndIf

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='mat-focus-indicator log-in-button mat-raised-button mat-button-base']")
$sRes= @error
if $sRes=$_WD_ERROR_Success then
    _WD_ElementAction($sSession, $sElement, 'click')
    _WD_LoadWait($sSession, 1000)
EndIf

Sleep (1000)

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//input[@id="idp-discovery-username"]')
$sRes= @error
If $sRes=$_WD_ERROR_Success then
    _WD_ElementAction($sSession, $sElement, 'value', "test@test.com")
    _WD_LoadWait($sSession,500)
EndIf

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@name='remember']")
;MsgBox ($MB_topmost,$sTitle,"$sElement: " & $sElement)
_WD_ElementAction($sSession, $sElement, 'selected')
_WD_LoadWait($sSession,500)


Exit
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='idp-discovery-submit']")
_WD_ElementAction($sSession, $sElement, 'click')
_WD_LoadWait($sSession,1000)


$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='okta-signin-password']")
_WD_ElementAction($sSession, $sElement, 'value', "Password")
_WD_LoadWait($sSession,1000)


$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='okta-signin-submit']")
_WD_ElementAction($sSession, $sElement, 'click')
_WD_LoadWait($sSession,3500)



KillChromeDriver ()             ; Kill Chromedriver

Func KillChromeDriver()             ; Kill Chromedriver.exe
    Local $aProcessList = ProcessList("chromedriver.exe")
    For $i = 1 To $aProcessList[0][0]
        ProcessClose($aProcessList[$i][1])
    Next
EndFunc


Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '')
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false,"prefs": {"credentials_enable_service": false}}}}}'
    $chromeloc = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
    If FileExists ("C:\Program Files\Google\Chrome\Application\chrome.exe") Then $chromeloc = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false,"prefs": {"credentials_enable_service": false}, "binary": "' & $chromeloc & '"}}}}'
EndFunc

 

Posted (edited)
  On 7/25/2022 at 7:55 PM, Jemboy said:

image.png.dad5306ff407f00f226ff258f1374839.png

Expand  

This screenshot shows a case when it is checked or not ?
Give us also the other case.

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

you can use:

document.querySelector("label[for='input34']").click()

or:

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "label[for='input34']"
_WD_ElementAction($sSession, $sElement, 'CLICK')

 

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)

@Jemboy

  1. Your post has been moved to this thread in the GH&S section (thanks to the @mod that moved it for me). General questions regarding the UDF belong here, not in the thread in the AutoIt Example Scripts section.
     
  2. Your attempt to check the checkbox using _WD_ElementAction / Select command will never work.
     
  3. Try using WD_ElementActionEx / Check command instead.
     
  4. I doubt that you will achieve the goal of a faster login unless you switch to using an existing user profile.
Edited by Danp2
Posted
  On 7/24/2022 at 8:02 PM, Danp2 said:

@HJL You need to correct your usage of "contains". See here for the correct format.

Expand  

Thanks, now I know how to use "contains". Are there other extras features for "contains" like changing uppercase to lowercase? If, where can I find them?

Next problem:  $_WD_LOCATOR_ByPartialLinkText does not work as expected or is there a thought error?

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@id="onetrust-accept-btn-handler"]')      ; works
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, '#onetrust-accept-btn-handler')          ; works
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByLinkText, 'onetrust-accept-btn-handler')              ; works
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByPartialLinkText, 'onetrust-accept-btn')               ; @error = 8
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByPartialLinkText, 'onetrust')                          ; @error = 8

 

Posted (edited)

What kind of replacement I can use for:

_IEAction($oElement, "scrollintoview", 200, 0, False)

?

 

EDIT:
Only with JavaScript ?
https://stackoverflow.com/a/20487332/5314940

?

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

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

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