使用Selenium WebDriver直接进行剪贴板操作(Direct clipboard manipulation with Selenium WebDriver)

编程入门 行业动态 更新时间:2024-10-23 18:31:56
使用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。

各种Selenium接口(Java,Python等)可以通过多种方式访问​​剪贴板函数,但这些只有在有问题的浏览器在包含它们的上下文中运行时才有效。 如果Selenium运行无头(意味着没有GUI,例如使用虚拟显示器,例如Xvfb ,可能作为虚拟机的一部分),可能没有任何可访问的具有剪贴板功能的上下文,而Selenium本身并不提供任何内容。

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.

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.

更多推荐

本文发布于:2023-04-28 00:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329669.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:剪贴板   操作   WebDriver   Selenium   clipboard

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!