Reputation: 512
I'm new to AutoIt and its library in Python PyAutoIt. I want my Python script to open Chrome browser, press ALT+D to go to the address bar of the Chrome browser, type https://www.yahoo.com
and press ENTER.
Here's my code which I tried to execute:
import autoit
autoit.run("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
autoit.send( "!d^ahttps://www.yahoo.com{ENTER}" )
Problem in this code is that it is writing the URL on my Python IDE also while writing it to the browser.
Just to mention that !d
means ALT+D and ^a
means CTRL+A.
OS: Windows 10 x64
Python IDE: Anaconda Spyder
PyAutoIt Version: 0.5
Upvotes: 1
Views: 2142
Reputation: 512
I did a bit of research on what michael_health said in the comment and found the following solution to the problem:
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}")
Upvotes: 4