【问题标题】:What are Selenium edgedriver Send Keys for select all and copy?什么是用于全选和复制的 Selenium edgedriver Send Keys?
【发布时间】:2021-02-09 17:36:45
【问题描述】:

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 驱动程序中复制的内容,所以它没有延续下来也就不足为奇了。

谢谢。

【问题讨论】:

    标签: selenium-webdriver copy sendkeys selectall selenium-edgedriver


    【解决方案1】:

    需要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 中的工作方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-13
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      • 2012-01-07
      相关资源
      最近更新 更多