页面上有一个按钮,当我单击“复制”时,会向剪贴板说出一个值。
我试图用 python selenium 将该值存储在变量中:
# Clicking the button using xpath will copy the value to Clipboard
value = driver.find_element_by_xpath('//*[@id="app-content"]/div/div[4]/div/div/div/div[1]/div/div/div/button').click()
# I try to print the value using
print(value)
Run Code Online (Sandbox Code Playgroud)
但我得到的结果是None.
请帮助我以正确的方式做到这一点。
提前致谢
首先,打印value没有意义,因为click()Selenium 中的函数不返回任何内容。您可以使用以下代码片段将剪贴板上的文本存储到变量中:
import tkinter as tk
root = tk.Tk()
root.withdraw() # to hide the window
variable = root.clipboard_get()
Run Code Online (Sandbox Code Playgroud)