Search code examples
pythonpython-3.xseleniumselenium-webdriverclipboard

Copy the link, once click on a button - selenium python


There is a button on the page that when I clicked copies a link. check the below image

enter image description here

I'm trying to store that link in a variable with python selenium this way:

surl=ii.find_element(By.XPATH, f'/html/body/div[1]/div[2]/div[5]/div[1]/div/div/div/section/div/div[2]/div/div[2]/div[1]/div/div/div/div[3]/div[2]/table/tbody/tr[str({row+1})]/td[6]/div/div/span/div/button')
furl = surl.send_keys(Keys.CONTROL + "c")

print(furl)

But I get the result as None. What is the issue here, Could someone help me with this?

Thank you.


Solution

  • By clicking that button the link is copied to the clipboard.
    There are several ways to get the text content from clipboard with Python. For example try this:

    from tkinter import Tk
    
    surl=ii.find_element(By.XPATH, f'/html/body/div[1]/div[2]/div[5]/div[1]/div/div/div/section/div/div[2]/div/div[2]/div[1]/div/div/div/div[3]/div[2]/table/tbody/tr[str({row+1})]/td[6]/div/div/span/div/button')
    surl.click()
    link = Tk().clipboard_get()
    print(link)