0

Selenium 非常新,事实上这是我在 VBA 中使用的第一个辅助库。

我正在使用 Microsoft Edge 的 Web 驱动程序,但无法弄清楚如何使用发送键,主要是选择页面的全部内容,然后将它们复制到剪贴板。

这就是我所拥有的

'''

 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

'''

对于某些人来说很明显,它在最后一行出现了错误,老实说,这正是我从我的 IE 驱动程序中复制的内容,所以它不会继续存在也就不足为奇了。

谢谢你。

4

1 回答 1

0

需要pip install undetected-chromedriver但也只能在普通的 selenium 和 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

print(driver.page_source)或者,如果您想要页面的全部内容,您也可以这样做。

我不知道 VBA,但这就是它在 python 中的工作方式。

于 2021-02-09T17:45:55.080 回答