This one seems simple, but has me going in circles. Looking for a way to enter values to input boxes on an open Microsoft Edge Browser page without Selenium references. Got it partially going with key presses. Couldn't get it to target input boxes.
I did come across this post: https://stackoverflow.com/a/71994505/4075963 Issue is account is locked from editing registry. I wasn't able to get CDP to identify and attach to an existing/open Edge Window. CDP would close other open windows and begin a new instance. Headache to make it through all the pages and program them. Maybe if it came down to is, I'll try starting here. IES couldn't locate Edge, IE mode was enabled.
I am able to successful run the code with Adobe. The format is consistent. The page when viewed in browser will sometimes have a checkbox that throws things out of line.
Requirements: Pre - To identify and activate/attach to existing Microsoft Edge Window. (Not that important.) I have it open and can just select the first input box.
- Enter starting number to B1.
- Enter number of total values needed to B3.
- The destination window is already open and first input box is activated. Script identifies the browser window by name.
- Script enters first value to input box.
- Go to next box.
- Script enters value + 1.
- Repeat until number of total values is met.
Problem: Base script works, I thought that it was lag somewhere that was throwing the tab key out of line. Attempt to add .01 second delay between the tab keys. Then realize the real issue is sometimes randomly there will be a checkbox in a few rows. So it throw off tab navigation.
Was seeing if there was another way. Maybe enable a shortcut function to move down input boxes and not next? Maybe send mouse clicks to webpage coordinates? Make it so that it will always click the same boxes or areas even if they are not visible?
Attempts/Failed: Identify locate/attached Windows Edge window. - Just didn't work out for me. Identify input box by id tag. - Didn't do anything. Identify input column index by number and letter. - It would being at the initial input box I activated, but would not move to the next.
Best Attempt: This was just mimicking raw key presses. Tab 3 times to get through and make it to the next row in the column. Problem was that sometimes there are random checkboxes that are in Column 1. This script works until a wild checkbox appears.
Input Destination
Sub SendBrowser()
Dim startValue As Double
Dim repeatCount As Long
Dim i As Long
' Read values from cells
startValue = CDbl(Range("B1").Value)
repeatCount = CLng(Range("B3").Value)
' Wait for 5 seconds
Application.Wait Now + TimeValue("00:00:05")
' Loop through and send keys with tab
For i = 1 To repeatCount
On Error Resume Next
AppActivate "Schedule"
On Error GoTo 0
If Err.Number <> 0 Then
MsgBox "Application 'Schedule' not found!"
Exit Sub
End If
SendKeys CStr(startValue), True
WaitMillis 100 ' Wait for 100 milliseconds
SendKeys "{TAB}", True
WaitMillis 100 ' Wait for 100 milliseconds
SendKeys "{TAB}", True
WaitMillis 100 ' Wait for 100 milliseconds
SendKeys "{TAB}", True
startValue = startValue + 1
Next i
End Sub
Sub WaitMillis(milliseconds As Long)
Dim startTime As Double
startTime = Timer
Do While Timer < startTime + (milliseconds / 1000)
DoEvents
Loop
End Sub