0

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.

  1. Enter starting number to B1.
  2. Enter number of total values needed to B3.
  3. The destination window is already open and first input box is activated. Script identifies the browser window by name.
  4. Script enters first value to input box.
  5. Go to next box.
  6. Script enters value + 1.
  7. 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

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
  • It looks like there is some problem in the method what you're trying to do, in this case, have you tried checking if the current [cell contains a checkbox](https://stackoverflow.com/questions/35921758/excel-vba-ckeck-if-cell-contains-a-checkbox#:~:text=Create%20and%20array%20of%20Range,know%20it%20contains%20a%20checkbox.)? On this basis, maybe you can execute one more keyboard `TAB` operation? – Xudong Peng Aug 28 '23 at 10:09
  • Figured it out to target the input boxes by name or id directly. Checking for checkboxes would be another way. Direct approach seemed to be more efficient. – Chris Choi Aug 30 '23 at 22:44

1 Answers1

0

SOLUTION: Was able to use this: https://github.com/longvh211/Edge-IE-Mode-Automation-with-IES-for-VBA

Input boxes in the column would be sorted after being generated. So they would be out of order. Instead of number order, I was able to get this to inset into the next available input box beginning with Schedule_txt. So instead of sendKey [tab], this targets the input boxes directly.

To make this work, you do need to set the title target of the Edge window. You also need the core module from the link above.

Edge automation works without Selenium.

Sub Input()
    Dim startValue As Double
    Dim repeatCount As Long
    Dim i As Long
   
    startValue = CDbl(Range("B1").Value)
    repeatCount = CLng(Range("B3").Value)

    titleToFind = "Scheduled"
    Set ieDoc = GetEdgeIeDOM(titleToFind)
    If ieDoc Is Nothing Then
        MsgBox "The webpage cannot be found on Edge IE Mode! Has it been loaded under Edge IE Mode?"
        End
    End If
   
    For i = 0 To repeatCount - 1
        Dim inputBoxes As Object
        Set inputBoxes = ieDoc.querySelectorAll("[id^='Schedule_txt']")
       
        If inputBoxes.Length > i Then
            inputBoxes.Item(i).Value = startValue
            startValue = startValue + 1 ' Increase startValue by 1
        Else
            MsgBox "No more input boxes with the specified ID pattern found."
            Exit Sub
        End If
    Next i
End Sub