首页 > 解决方案 > 将剪贴板中的链接作为 URL 粘贴到下一个窗口

问题描述

我想将剪贴板链接复制并粘贴到新打开的浏览器选项卡。新标签正在打开,但没有任何反应。结果中的剪辑方法具有此 url 链接,但出现错误。到目前为止我所拥有的:

def switch_tab(self):
        self.driver.execute_script("window.open('');")
        self.driver.switch_to.window(self.driver.window_handles[len(self.driver.window_handles) - 1])
        time.sleep(2)
        self.driver.get(clip)

和剪辑方法

def clip():
    r = Tk()
    r.withdraw()

    while not r.selection_get(selection="CLIPBOARD"):
        time.sleep(0.1)

    result = r.selection_get(selection="CLIPBOARD")
    print(result)
    return result

File "C:\Users\AppData\Local\Programs\Python\Python38\lib\json\encoder.py", line 179, in default
          raise TypeError(f'Object of type {o.__class__.__name__} '
      TypeError: Object of type function is not JSON serializable

标签: pythonselenium-webdriver

解决方案


推荐阅读