I'm in trouble because the code doesn't work as expected.
I would appreciate it if you could let me know how to fix it.
Python 2.7
Windows 7
Paste pre-saved gazou1.png and gazou2.png on Gmail's email creation screen
以下 I saved it in filepath2 of the code below
Open the image with paint and copy it with pyautogui → paste it → paste it into the body of Gmail → Ctrl+Z to restore the original image size.
The first image often fails to paste.
Or rather, autobooting from the task scheduler almost fails (about 20% success rate).
Running the py file manually almost succeeds.
Open gazou1 with paint and Ctrl+A to make all selections successful
Subsequent Ctrl+C does not work on the paint screen.
When you focus on the text and paste , the most recently copied string is
Paste into the body of the email→Cancel the action with Crtl+Z
This phenomenon has occurred.
By the way, pasting the second image has always been successful.
filepath2=u "C:\photo\"
app="C:\Windows\System32\mspaint.exe"
file=filepath2+u "gazou1.png"
pro=subprocess.Popen ([app, file])
time.sleep(3)
pyautogui.hotkey('ctrl', 'a')
pyautogui.hotkey('ctrl','c')
elements=driver.find_element_by_xpath(u"//*[@class='Am Aleditable LW-avf']")
elements.send_keys (Keys.ENTER)
ActionChains(driver).key_down(Keys.CONTROL).send_keys('v').key_up(Keys.CONTROL).perform()
time.sleep(16)
ActionChains(driver).key_down(Keys.CONTROL).send_keys('z').key_up(Keys.CONTROL).perform()
time.sleep(4)
pro.kill()
time.sleep(3)
app="C:\Windows\System32\mspaint.exe"
file=filepath2+u "gazou2.png"
pro=subprocess.Popen ([app, file])
time.sleep(3)
pyautogui.hotkey('ctrl', 'a')
pyautogui.hotkey('ctrl','c')
elements=driver.find_element_by_xpath(u"//*[@class='Am Aleditable LW-avf']")
elements.send_keys (Keys.ENTER)
ActionChains(driver).key_down(Keys.CONTROL).send_keys('v').key_up(Keys.CONTROL).perform()
time.sleep(16)
ActionChains(driver).key_down(Keys.CONTROL).send_keys('z').key_up(Keys.CONTROL).perform()
time.sleep(4)
pro.kill()
time.sleep(3)
Based on the answers you gave me, I carried it out.
Unfortunately, similar symptoms have occurred and have not been successful.
Therefore, based on our way of thinking, I changed it as follows and it started to move steadily.
■Changed parts
filepath2=u"C:\\photo\\"
バックChange backslash to description twice in a row
Thank you to everyone who checked.
I don't know if it's the root cause, but if you use the backslash \
in the string, it will be escaped, so I think the second "
in the first line is escaped and the string is not closed.That's why StackOverflow's syntax highlights are weird.
When specifying a path in Python, you can usually use forward slash /
even on Windows, so for now
filepath2=u"C:/photo/"
app="C:/Windows/System32/mspaint.exe"
Why don't you try it?
I mean, I think it's more mysterious to move 20% of the time...
© 2024 OneMinuteCode. All rights reserved.