https://blog.csdn.net/fnms88/article/details/82926051
直接代码如下:
import autoit
import unittest
import time
import sys
from datetime import datetime
from actions import Actions
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
sys.path.append(‘D:\jftest1_CG\test1’)
class Test_Newyyy_pctz_shfk (unittest.TestCase):
def test_pcLogin(self):
fp = webdriver.FirefoxProfile(r"C:\Users\mhf\AppData\Roaming\Mozilla\Firefox\Profiles\cv6txwo2.default")
driver = webdriver.Firefox(fp)
driver = webdriver.Firefox ()
driver.get (“https://www.csdn.net/”)
WebDriverWait (driver, 10).until (EC.presence_of_element_located ((By.LINK_TEXT, ‘博客’)))
#获取浏览器窗口
autoit.win_activate(‘CSDN-专业IT技术社区 - Mozilla Firefox’)
print(“1111”)
autoit.send(’{LCTRL down}’+’{LSHIFT down}’+’{! down}’)
autoit.send(’{LCTRL down}’ + ‘{LALT down}’ + ‘{a down}’)
driver.find_element_by_id(‘login’).send_keys(Keys.CONTROL + Keys.SHIFT + ‘!’)
time.sleep(2)
autoit.win_wait(‘截取的图片另存为…’)
print(“2222”)
autoit.control_focus(‘截取的图片另存为…’,‘1001’)
print(“3333”)
autoit.win_wait("[Class:#32770]",10)
t = datetime.now().strftime(’%Y%m%d%H%M%S’)
name=‘百度首页’+t
autoit.control_set_text(‘截取的图片另存为…’,‘Edit1’,name)
autoit.control_click(‘截取的图片另存为…’,‘Button2’)
1111111
#最后再点击一次shift键 释放长按shift ,以免后续操作不方便,点哪都觉得不好使,解铃还须系铃人(autoit)。。。
autoit.send (’{LCTRL}’ + ‘{LSHIFT}’)
driver.close()
if name == ‘main’:
unittest.main ()
可以实现整个网页的截图
官方的例子,也可参考:
import autoit
import time
autoit.run(“notepad.exe”)
autoit.win_wait_active("[CLASS:Notepad]", 3)
autoit.control_send("[CLASS:Notepad]", “Edit1”, “hello world{!}”)
autoit.win_close("[CLASS:Notepad]")
time.sleep(100)
autoit.control_click("[Class:#32770]", “Button2”)
time.sleep(100)
python的模块pywin32 可以释放按键
import win32api
import win32con
win32api.keybd_event (17, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放按键ctrl
win32api.keybd_event (16, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放按键shift