Jump to content

Recommended Posts

Hi all!

I have a problem with sending combination of control and key. Script always send only key without ctrl effect in any application.

I tried

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

HotKeySet("{ESC}","Quit")

Local $sDesiredCapabilities, $sSession
SetupChrome()

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

; Login
_WD_Navigate($sSession, "https://accounts.google.com/signup/v2/webcreateaccount?continue=https%3A%2F%2Fwww.google.com%2F&hl=vi&dsh=S-553103207%3A1653362446062875&biz=false&flowName=GlifWebSignIn&flowEntry=SignUp")

Local Const $ExcelFile = @ScriptDir & "\_Excel1.xls"
$oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error starting", "@error = " & @error)
$oWorkbook = _Excel_BookOpen($oExcel, $ExcelFile)
$bOpenWorkBook = True
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error opening workbook","@error = " & @error)

$lastrow = $oExcel.ActiveSheet.UsedRange.Rows.Count 

Local $browser = WinWait("[TITLE:Google - Google Chrome]", "", 10)
Local $excel= WinWait("[CLASS:XLMAIN]", "", 10)

For $iRow = 2 To $lastrow step + 1
    ;===========Copy Column A
     WinActivate($excel)
    Sleep(500)
    $sCell = _Excel_RangeRead($oWorkbook, Default, "A" & $iRow) ;~ Workbook was opened so read cell A2
    Sleep(500)
    WinActivate($browser)
    Sleep(500)
    _ChromeSetInputValueByElement($sSession, 'id' ,'lastName', Send("^a"))
    
    Sleep(500)
    _ChromeSetInputValueByElement($sSession, 'id' ,'lastName', $sCell )
    
    ;===========Copy Column B
     WinActivate($excel)
    Sleep(500)
    $sCell = _Excel_RangeRead($oWorkbook, Default, "B" & $iRow) ;~ Workbook was opened so read cell A2
    Sleep(500)
    WinActivate($browser)
    Sleep(500)
    _ChromeSetInputValueByElement($sSession, 'id' ,'firstName', Send("^a"))
    Sleep(500)
    _ChromeSetInputValueByElement($sSession, 'id' ,'firstName', $sCell )
    
    ;===========Copy Column C
     WinActivate($excel)
    Sleep(500)
    $sCell = _Excel_RangeRead($oWorkbook, Default, "C" & $iRow) ;~ Workbook was opened so read cell A2
    Sleep(500)
    WinActivate($browser)
    Sleep(500)
    _ChromeSetInputValueByElement($sSession, 'id' ,'username', Send("^a"))
    Sleep(500)
    _ChromeSetInputValueByElement($sSession, 'id' ,'username', $sCell )
    
Next 
 
Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    ;_WD_Option("DefaultTimeout", 1000)
    
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--disable-infobars"]}}}}'
    
EndFunc

;_WD_DeleteSession($sSession)
;_WD_Shutdown()
Func _ChromeSetInputValueByElement($sSession, $Elm, $Id, $Value)
    $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@" & $Elm & "='" & $Id & "']")
    _WD_ElementAction($sSession, $sButton, 'value', $Value)
EndFunc   ;==>_ChromeSetInputValueById

Func _WD_ElementValue($sKey, $Value)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sKey)
    _WD_ElementAction($sSession, $sElement, 'value', $Value)
EndFunc   ;==>_WD_ElementValue

Func _WD_ElementClick($sKey)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sKey)
    _WD_ElementAction($sSession, $sElement, 'click')
EndFunc 
    
Func Quit()
    Exit
EndFunc

but pasting in the input, the result is pasting the number 1 and the copied text.

Ex: Copy abcde, Paste: 1abcde

Please help me :((

Link to post
Share on other sites

Funny that, I was just looking up the documentation for the SEND function the other day in the AutoIt help file, and was wondering about the option flag (default/raw), and noticed the examples didn't show much for the second option.

The SendKeyList wasn't of much use either.

I experimented, had to split my strings into some of one and some of the other, all ending up concatenated, and it turned out OK, but not really sure why.

I'll go back and read a bit further later, but in the meantime my code is working.

Good luck with the documentation. A little bit of flushing out of examples may be in order.

Link to post
Share on other sites
Posted (edited)

PS: I went back in to the help file and there is one example in (wait for it), Frequently Asked Questions (FAQ), Item 6 to be specific.

Matthew 7:7-8, King James Version
 

 

 
 

 

Edited by Confuzzled
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...