0

Very new to Selenium, in fact this is the first auxiliary library I am using in VBA.

I'm using the Web Driver for Microsoft Edge, and I'm having trouble figuring out how to use send keys, mainly to select the entire contents of the page and then copy them to the clipboard.

here is what I have

'''

 Sub Send_Keys_CTRL_A_Ctrl_C()

     Dim obj As New WebDriver

     obj.Start "edge", ""
     obj.Get "http://www.google.com"
     Application.Wait (Now + TimeValue("0:00:01"))
     obj.FindElementByClass("body").SendKeys (Keys.Control + "a" + 
     Keys.Control)

End Sub

'''

As is obvious to some most likely, it bugs out on the last line, which is quite honestly just what I copied from my IE drivers, so no surprise that it doesn't carry over.

Thank you.

1 Answers1

0

Requires pip install undetected-chromedriver but will also just work in normal selenium and edgedriver.

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

import undetected_chromedriver as uc
options = uc.ChromeOptions()
options.headless = False
driver = uc.Chrome(options=options)

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body'))).send_keys(Keys.CONTROL, 'a') #press ctrl + a
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'body'))).send_keys(Keys.CONTROL, 'c') #press ctrl + c

or you could also just do print(driver.page_source) if you want the entire content of the page.

I don't know VBA, but this is how it works in python.

Mika C.
  • 70
  • 1
  • 14