selenium3 +のpython - AutoItのアップロードファイル

まず、準備するための環境:

1. AutoItの公式ウェブサイトでは、インストール、ダウンロードすることができます  http://www.autoitscript.com/site/を

 いくつかのメニューの特長があります2.AutoIt:

  • ここSciTEのスクリプトエディタエディタのAutoItスクリプトの書き込み
  • AutoItのWindowsの情報要素ロケータ、情報は、Windowsのコントロールを識別するために使用されます
  • スクリプトの実行のAutoItスクリプトの実行
  • スクリプトをコンパイルしto.exeはAutoItの.exe実行ファイルを生成します。

   3.autoit  オンラインドキュメント、中国語版http://www.autoitx.com/Doc/

第二に、スクリプトの実装:

1.写真をアップロードするために、ご使用の環境の良いWebページを作成し、例として公園ブログ:>ローカルの画像をアップロードする画像を選択するポップアップ画面を新しいエッセイ>ポイント画像アップロード>を追加し、ここでは移動しないでください

 

 

2. SciTEのスクリプトエディタエディタは、スクリプトを記述するために始めた、コードは非常にシンプルであり、唯一の4行

 

WinActivate( "開きます");

ControlSetText( "打开"、 ""、 "EDIT1"、 "F:\ 11.png");

スリープ(2000);

ControlClick( "打开"、 ""、 "ボタン1");

実行が成功をアップロードした写真を見ることができます後、またはF5キーで実行される; 3>の編集、ツールの後実行して行きます。

4.autoitいくつかの一般的な文法

  • アクティブウィンドウのフォーカスを指定するWinActivate(「タイトル」)
  • ControlFocus ( "title", "窗口文本", controlID) 设置输入焦点到指定窗口的某个控件上;
  • WinWait ( "title" , "窗口文本" , 超时时间 ) 暂停脚本的执行直至指定窗口存在(出现)为止;
  • ControlSetText ( "title", "窗口文本", controlID, "新文本" ) 修改指定控件的文本;
  • Sleep ( 延迟 ) 使脚本暂停指定时间,单位是毫秒;
  • ControlClick ( "title", "窗口文本", 控件ID , 按钮 , 点击次数 ) 向指定控件发送鼠标点击命令;

三、元素定位

1.Find Tool 查看元素属性,用鼠标按住Find Tool下的图标,然后拖拽到你想定位的元素上

2.查看controlID,controlID即AutoIt Window Info识别出的Class和Instance的拼接

 四、导出exe文件

在应用程序里面找到打开Compile Script to.exe工具,将刚才导出的.au3文件转化成.exe文件 

 
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import os,time

'''登录博客'''
driver = webdriver.Chrome()
driver.get("https://passport.cnblogs.com/user/signin")
driver.implicitly_wait(10)

"""账号和密码登录"""
driver.find_element_by_id("LoginName").send_keys("xxxx")
driver.find_element_by_id("Password").send_keys("xxx")
driver.find_element_by_id("IsRemember").click()
login = WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.ID,"submitBtn")))
login.click()

driver.find_element_by_link_text("我的博客").click()
time.sleep(2)
driver.find_element_by_link_text("发新随笔").click()
time.sleep(2)
# 点开编辑器图片
driver.find_element_by_css_selector("img.mceIcon").click()
time.sleep(3)
#定位所有iframe,取第二个
iframe = driver.find_elements_by_tag_name("iframe")[1]
#切换到iframe上
driver.switch_to_frame(iframe)
print(iframe)
#点击上传文件按钮
submit = WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.NAME,"file")))
submit.click()
# js = 'document.getElementByName("file").click();'
# driver.execute_script(js)
# 执行autoit上传文件
os.system(r"C:\Users\Administrator\Desktop\sendfile.exe")

おすすめ

転載: www.cnblogs.com/Teachertao/p/10993622.html