以下代码使用Selenium和xsel,并且在驱动程序从网页复制到剪贴板的某些内容后,预计会提取剪贴板内容:
import unittest
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import subprocess
class Test(unittest.TestCase):
def run(self):
self.driver = webdriver.Firefox()
self.driver.get('some_uri')
self.wait = WebDriverWait(self.driver, 20)
link_elem = self.wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "i[data-original-title='Copy to clipboard']")))
link_elem.click()
self.wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "i[data-original-title='Copied']")))
link = subprocess.check_output(["xsel"])
print(link)
剪贴板内容被打印,但它不是由python代码复制的内容,而是来自过去的一些剪贴板内容。如何正确提取剪贴板内容?