Reputation: 193
There is a button on the page which when I clicked copies, say a value to the clipboard.
I'm trying to store that value in a variable with python selenium this way:
# 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)
But I get the result as None
.
Kindly help me in doing this in correct way.
Thanks in Advance
Upvotes: 2
Views: 4461
Reputation: 1
First of all thanks @Muhteva for the solution, it helped me. But when I tried it with the headless mode I took this error:
_tkinter.TclError: CLIPBOARD selection doesn't exist or form "STRING" not defined
PS: it works well when the headless mode is disabled
Upvotes: 0
Reputation: 2832
First of all, printing the value
is not meaningful because click()
function in Selenium doesn't return anything. You can store the text on your clipboard to a variable with this snippet:
import tkinter as tk
root = tk.Tk()
root.withdraw() # to hide the window
variable = root.clipboard_get()
Upvotes: 5