selenium 通过剪切板粘贴(Command+v)方式,向输入框输入内容

code

import os
import sys
import time
import pyperclip
from selenium import webdriver 
from selenium.webdriver.common.keys import Keys


mobileEmulation = {'deviceName' :'Galaxy S5'}

option=webdriver.ChromeOptions()

option.add_experimental_option('mobileEmulation',mobileEmulation)

charome = webdriver.Chrome(options=option)
charome.get("https://xxx.com/login")

charome.implicitly_wait(3.5)
charome.find_element_by_xpath(".//input[@placeholder='请输入手机号']").click()

pyperclip.copy("135xxxxxxxx") #在剪切板中插入需要粘贴的文本内容
time.sleep(2)
charome.find_element_by_xpath(".//input[@placeholder='请输入手机号']").send_keys(Keys.COMMAND,'v')

charome.implicitly_wait(3.5)
charome.find_element_by_xpath(".//input[@placeholder='请输入验证码']").click()
charome.find_element_by_xpath(".//input[@placeholder='请输入验证码']").send_keys("8888")

原文地址:https://www.cnblogs.com/sea-stream/p/14262228.html