使用Selenium WebDriver直接剪贴板操作 [英] Direct clipboard manipulation with Selenium WebDriver
问题描述
是否可以使用Selenium WebDriver在剪贴板中预先填充一些要粘贴的文本,就像该文本已在另一个应用程序中复制一样? (理想情况下使用Python绑定吗?)
Is it possible to use Selenium WebDriver to pre-populate the clipboard with some text to be pasted, as though the text had been copied in another application? (Ideally using the Python bindings?)
推荐答案
不,似乎不是–作为浏览器的操纵工具,Selenium旨在执行浏览器特有的功能.通常,剪贴板操作是由文件管理器处理的功能,通常包括GUI(例如Windows资源管理器或Mac OS Finder).
No, it seems not – as a browser manipulation tool, Selenium is designed to perform functions unique to browsers. In general, clipboard manipulation is a function handled by a file manager, usually one which includes a GUI, such as Windows Explorer or the Mac OS Finder.
有 种方式供各种Selenium接口(Java,Python等)访问剪贴板函数,但是只有当所涉及的浏览器在包含它们的上下文中运行时,这些方法才起作用.如果Selenium无头运行(这意味着没有GUI,例如使用诸如 Xvfb 之类的虚拟显示器)作为虚拟机的一部分)可能没有任何具有剪贴板功能的可访问上下文,Selenium本身也不提供任何功能.
There are ways for the various Selenium interfaces (Java, Python, etc) to access clipboard functions, but these only work if the browser in question is running in a context which contains them. If Selenium is running headless (meaning with no GUI, e.g. using a virtual display such as Xvfb, possibly as part of a virtual machine) there may not be any accessible context with clipboard functionality, and Selenium itself does not provide any on its own.
这篇关于使用Selenium WebDriver直接剪贴板操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!