复制到剪切板
driver.execute_script("""
var textArea = document.createElement('textarea');
textArea.setAttribute('id','w_clipboard_temp_el');
document.body.appendChild(textArea);
""")
driver.find_element(By.ID, 'w_clipboard_temp_el').send_keys(text)
driver.execute_script("""
var textArea = document.getElementById('w_clipboard_temp_el');
textArea.select();
document.execCommand('copy');
textArea.remove();
""")
获取剪切板的文本
driver.execute_script("""
var textArea = document.createElement('textarea');
textArea.setAttribute('id','w_clipboard_temp_el');
document.body.appendChild(textArea);
""")
driver.find_element(By.ID, 'w_clipboard_temp_el').send_keys(Keys.CONTROL, 'v')
text = driver.find_element(By.ID, 'w_clipboard_temp_el').get_attribute('value')
driver.execute_script("""
var textArea = document.getElementById('w_clipboard_temp_el');
textArea.remove();
""")
个人博客链接:nick的开发博客