Selenium-PythonBindings,为什么此脚本在ATOM中起作用,但在TaskScheduler中不起作用

时间:2019-07-17 00:45:21

标签: python selenium selenium-webdriver binding selenium-chromedriver

我有一个脚本,该脚本使用硒来启动chrome并在市场网站上导航,登录并点击下载按钮。

该下载按钮将启动一封电子邮件,发送到我们的交换服务器,在这里我对URL进行了字符串切片,然后将其放回相同的chrome会话中进行下载。

由于某种原因,当我通过命令行或在atom中手动运行它时,这很好。但是,当我将其填充到任务计划程序中时(通过批处理文件或通过启动程序=“ python”(位于PATH中)并且参数=“脚本路径”,脚本似乎在任务计划程序中“运行”了预期的状态时间(我有300秒的睡眠),然后结束而没有任何反应。

我认为这与Chrome下载设置有关。当我从taskchduler运行任务时,没有得到python或chrome窗口(我使用的是python,而不是pythonw)。我尝试过在打开时将其添加到Chrome设置中,而我似乎得到的只是Chrome窗口中的“下载错误”。

本地计算机的“下载”文件夹中没有任何反应。

当我手动运行它时,下载会顺利进行,并且会出现downloads文件夹。

此外,当我使用手动将python泵入批处理文件时 @echo off和python -x“%〜f0”%*&goto:eof 导入系统

它在运行时有相同的问题,但没有下载。我在这里尽头。有人能帮忙吗?

以下是它们在任务管理器中的当前设置(当我手动单击该bat文件时,它会打开chrome并运行并下载,一切正常) https://imgur.com/a/sF96pup https://imgur.com/a/tufTGIM

#Import Selenium things
import time;
from selenium import  webdriver;
from selenium.webdriver.common.keys import Keys;
from selenium.webdriver.support import expected_conditions as EC;
import subprocess;
#import wget


#ImportExchangeThings
from exchangelib import DELEGATE, IMPERSONATION, Account, Credentials, ServiceAccount, \
EWSDateTime, EWSTimeZone, Configuration, NTLM, CalendarItem, Message, \
Mailbox, Attendee, Q, ExtendedProperty, FileAttachment, ItemAttachment, \
HTMLBody, Build, Version

#Load up that Driver
driver = webdriver.Chrome('C:\\Selenium\\WebDrivers\\Chromedriver.exe')

#Head to the Website and make sure it has enough time to load
driver.get('<WEBSITEREDACTED>');
print('Starting wait for houzz page to load')
time.sleep(5)
print('wait over')

#Enter Username Element
username = driver.find_element_by_class_name("hzhp-signup__input")
username.send_keys("<EMAILREDACTED>")
password = driver.find_element_by_id("password")
password.send_keys("<PWREDACTED>")
password.send_keys(Keys.RETURN)

#Wait for Login to take
print('Waiting for Login to take')
time.sleep(5)
print('wait over')

#Head to the Inventory Page
inventorypage = driver.get('<WEBSITEREDACTED>')
print('Starting wait for Inventory Page to Load')
time.sleep(7)
print('wait over')

#hit download button
downloadbutton = driver.find_element_by_id('downloadBtn').click()
time.sleep(1)
downloadconfigbutton = driver.find_element_by_id('hzConfirmDlgOKBtn')
print('The value is ', downloadconfigbutton)
downloadconfigbutton.send_keys(Keys.RETURN)

#wait for exchange to receive mail
time.sleep(300)

# Connect to Exchange, grab the correct folder, stringslice the last inventory URL out of the most recent email.
print("connecting to exchange server")
creds = Credentials(
username="<REDACTED>",
password="<REDACTED>")

config = Configuration(server='<WEBSITEREDACTED>', credentials=creds)

account = Account(
primary_smtp_address="<WEBSITEREDACTED>",
autodiscover=False,
config = config,
access_type=DELEGATE)

print('connected!')

#Define the Folder
inventoryfolder = account.inbox / 'Inventory'

#find most recent file in Folder
print('grabbing most recent email in inventory folder')
for item in inventoryfolder.all().order_by('-datetime_received')[:1]:
    #print(item.body.encode('utf-8'))
    #Define EMailBody and Slice the URL out of it
    emailbody = item.body.encode('utf-8')
    emailbodyindex1 = emailbody.find('<REDACTED>')
    print ("The begginging of the link is located at", emailbodyindex1)
    emailbodyindex2 = emailbody.find('.zip')
    print ("The begginging of the link is located at", emailbodyindex2)
    print (emailbody[emailbodyindex1:(emailbodyindex2+4)])
    finalurl = (emailbody[emailbodyindex1:(emailbodyindex2+4)])


#Download the file with wget
print('the url for our download is.............',finalurl)
print('opening chrome again to grab the download')

driver.get(finalurl)


time.sleep(15)

#Call a Powershell Script to Rename and Move some files around
subprocess.call(['C:\\Windows\System32\\WindowsPowerShell\\v1.0\\powershell.exe','C:\\Scripts\\Houzz-Move.ps1'])

0 个答案:

没有答案