0

I want to automate Chrome from Excel VBA. I am using the framework mentioned in : (Method 2 in the answer)

Automating Edge Browser using VBA without downloading Selenium

where in github located

https://github.com/longvh211/Chromium-Automation-with-CDP-for-VBA

In the browser I want to automate, there is a search input and looking at the sample I can select the input like this

chrome.jsEval "el = document.evaluate(""//input[contains(@placeholder,'Search')]"", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"

And I can change its value like :

chrome.jsEval "el.value = """ & WorkSheet.Cells(2, 3) & """"

However the input has autocomplete (typeahead) and when I change its value like above, it doesn't filter the table below it. I believe I should send the value by sendkey like in Selenium, but couldn't figure out how to do this with this framework.

I would appreciate any help on this issue.

  • Try "el.focus(); document.execCommand('insertText', false, """ & WorkSheet.Cells(2, 3) & """)" – wOxxOm Feb 04 '23 at 01:37
  • Try also CDP methods like [Input.insertText](https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-insertText). – wOxxOm Feb 04 '23 at 01:38
  • @wOxxOm thanks a lot for your suggestions, Try "el.focus(); document.execCommand('insertText', false, """ & WorkSheet.Cells(2, 3) & """)" worked like a charm. Please make it as answer so I can tag it as the answer. Also can you please give advice how can I use CDP methods you have mentioned in your second comment (like Input.insertText) and if there are any samples that I can find for CDP comments, thank you – st_user_321122 Feb 04 '23 at 09:15
  • And one more question, if you can help. There is a Select2 to choose 1 option, but when I enter the value in it, it shows 2 different values with additional text in it (it has an additional text to the right where that additional value goes to another input) and I have to choose any one of them. Is there a way to select options with CDP? (It doesn't accept the value with the method you suggested even tough you enter the value with additional text) – st_user_321122 Feb 04 '23 at 10:44
  • I don't know about VBA+CDP, so it might be better if you find that info and post an answer with both approaches. – wOxxOm Feb 04 '23 at 11:16
  • OK thank you, I switched to Selenium VBA, it has more documentation and examples – st_user_321122 Feb 04 '23 at 11:27

0 Answers0