【问题标题】:Python - Automating Chrome to start and enter URL in address bar using autoitPython - 使用 autoit 自动启动 Chrome 并在地址栏中输入 URL
【发布时间】:2018-12-07 18:47:21
【问题描述】:

我是 AutoIt 及其 Python 库的新手PyAutoIt。我想让我的 Python 脚本打开 Chrome 浏览器,按 ALT+D 转到 Chrome 浏览器的地址栏,输入 https://www.yahoo.com 并按 ENTER.

这是我尝试执行的代码:

import autoit

autoit.run("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
autoit.send( "!d^ahttps://www.yahoo.com{ENTER}" ) 

此代码中的问题是它正在我的 Python IDE 上写入 URL,同时将其写入浏览器。

只是提到!d 表示 ALT+D^a 表示 CTRL+A .

操作系统:Windows 10 x64
Python IDE:Anaconda Spyder
PyAutoIt 版本:0.5

【问题讨论】:

  • 您运行chrome.exe,无需等待窗口显示,您就发送了一系列操作。我怀疑您是否会手动将操作发送到未显示的窗口。查看pyautoit 网站首页底部关于自动化记事本的示例。
  • 您是绝对正确的@michael_health,我正在编辑问题以将autoit.win_wait_active("New Tab", timeout=10) 添加到代码中,这会将chrome 浏览器窗口设置为活动窗口。

标签: python-3.x autoit


【解决方案1】:

我对michael_health在评论中所说的做了一些研究,并找到了以下问题的解决方案:

import autoit
import time

google_chrome_pid = autoit.run('"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -incognito', show_flag=3) # run in incognito mode, start maximized
autoit.win_wait_active("New Tab", timeout=10) # active window 
time.sleep(3)
autoit.opt("SendKeyDelay", 100) # Slow down typing to 100 milliseconds
autoit.send("!dhttps://www.yahoo.com")
time.sleep(2)
autoit.send("{ENTER}")

【讨论】:

    猜你喜欢
    • 2015-01-11
    • 1970-01-01
    • 2014-03-29
    • 2016-04-09
    • 2014-10-07
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多