selenium环境安装
pip3 install selenium
http:
#将安装包加入到环境变量。以mac系统为例,将chromedriver移至/usr/bin目录下
mv ~/Downloads/chromedriver /usr/bin
Mac键盘、鼠标控制
import time
'''
使用pykeyboard发现回车不起作用,所以采用pynput
'''
def my_return():
from pynput.keyboard import Key, Controller
keyboard = Controller()
keyboard.press(Key.enter)
time.sleep(2)
keyboard.release(Key.enter)
keyboard.press(Key.enter)
time.sleep(2)
keyboard.release(Key.enter)
'''
处理web文件上传问题,自动定位到指定文件,选中确认
'''
def upload_file_mac(file):
import pyperclip
from pymouse import PyMouse
from pykeyboard import PyKeyboard
pyk = PyKeyboard()
pym = PyMouse()
time.sleep(2)
print("Command+Shift+G")
pyk.press_keys(['Command', 'Shift', 'G'])
x_dim, y_dim = pym.screen_size()
pym.click(x_dim // 2, y_dim // 2, 1)
time.sleep(2)
pyperclip.copy(file)
print("copy="+file)
pyk.press_keys(['Command', 'V'])
my_return()
作者
jnan77
发表于
2020-02-25 14:45:44
,最后修改于
2020-02-26 22:51:46
Comments