[英]copy and paste in selenium python
I'm new to selenium I am trying to copy something from one page to another, the page that I copy off of already has it so if you just click on the text once it copies automatically but it is not copying anything I am not sure why我是 selenium 的新手 我正在尝试将某些内容从一页复制到另一页,我复制的页面已经有了它,所以如果您在文本自动复制后单击它,但它没有复制任何东西,我不确定为什么
chrome_driver = '/Applications/chromedriver'
driver = webdriver.Chrome(chrome_driver)
driver.get('https://tempail.com/en/')
time.sleep(5)
driver.find_element_by_xpath('//*[@id="eposta_adres"]').click()
driver.get('https://www.instagram.com/')
driver.find_element_by_xpath('//*[@id="user_first_name"]').send_keys('Scott')
driver.find_element_by_xpath('//*[@id="user_email"]').click()
act.key_down(Keys.META).send_key("COMMAND + v").key_up(Keys.META).perform()
On my Linux
in Firefox
and Chrome
works在我的Linux
中的Firefox
和Chrome
上工作
item.send_keys(Keys.CONTROL, "v")
Like喜欢
item = driver.find_element_by_xpath('//*[@id="user_email"]')
item.send_keys(Keys.CONTROL, "v")
I tried to test it with your code but you use xpath
which I can't find on Instagam
我尝试用您的代码对其进行测试,但您使用的是我在xpath
上找不到的Instagam
So I tested with field Search...
on current page所以我在当前页面上使用字段Search...
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
#from webdriver_manager.firefox import GeckoDriverManager
import time
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
#driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
driver.get('https://tempail.com/en/')
time.sleep(5)
driver.find_element_by_xpath('//*[@id="eposta_adres"]').click()
driver.get('https://stackoverflow.com/questions/71543113/copy-and-paste-in-selenium-python/')
item = driver.find_element_by_xpath('//*[@name="q"]')
item.send_keys(Keys.CONTROL, "v")
BTW: I described this long time ago in顺便说一句:我很久以前在
Selenium: How to send clipboad to field in browser — furas.pl . Selenium:如何将剪贴板发送到浏览器中的字段 — furas.pl 。
I show also how to use module pyperclip to work with clipboard
.我还展示了如何使用模块pyperclip来处理clipboard
。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
#from webdriver_manager.firefox import GeckoDriverManager
import time
import pyperclip
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
#driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
driver.get('https://stackoverflow.com/questions/71543113/copy-and-paste-in-selenium-python/')
item = driver.find_element_by_xpath('//*[@name="q"]')
#text = pyperclip.paste() # get text from cliboard
#item.clear()
#item.send_keys(text)
pyperclip.copy("Hello World") # put text in clipboard
item.send_keys(Keys.CONTROL, "v")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.