启动应用程序没有运行我的脚本

启动应用程序没有运行我的脚本

我在启动应用程序中添加了一项,如下所示:

编辑启动程序

为了您的方便,我在这里重复该命令:

gnome-terminal --command  "sleep 30;export PATH=$PATH:/home/erik/Downloads/geckodriver_dir;python ~/Dropbox/BashScripts/fjucheckin.py"

按理说,我进办公室后打开笔记本,会打开一个 gnome 终端,然后运行 ​​python 脚本fjucheckin.py打开一个 Firefox 窗口,然后自动帮我签到,然后等我按某个键关闭 Firefox 窗口。但结果发现,没有出现 gnome 终端或 Firefox 窗口。

之后我手动运行了上述整个gnome-terminal --command "sleep 30;export PATH=$PATH:/home/erik/Downloads/geckodriver_dir;python ~/Dropbox/BashScripts/fjucheckin.py"命令,一个终端出现并在一秒钟内关闭。没有出现任何 Firefox 窗口。

sleep 30;export PATH=$PATH:/home/erik/Downloads/geckodriver_dir;python ~/Dropbox/BashScripts/fjucheckin.py手动运行它,并且它起作用了。

python脚本fjucheckin.py如下,如果需要的话:

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
#import org.openqa.selenium.support.ui.Select;
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.implicitly_wait(1000) # seconds
driver.get("http://140.136.251.114/Aiamis/Login.aspx")
#assert "Python" in driver.title

#Account
elem = driver.find_element_by_name("ctl00$ContentPlaceHolder$txtAccount")
elem.clear()
elem.send_keys("...")
elem.send_keys(Keys.TAB)
assert "No results found." not in driver.page_source

#Password
elem = driver.find_element_by_name("ctl00$ContentPlaceHolder$txtPwd")
elem.clear()
elem.send_keys("...")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source

#// Get a handle to the open alert, prompt or confirmation
WebDriverWait(driver, 1000).until(EC.alert_is_present())
alert = driver.switch_to.alert;
#// And acknowledge the alert (equivalent to clicking "OK")
alert.accept();

elem = driver.find_element_by_link_text("差勤/日誌填寫");
hover = ActionChains(driver).move_to_element(elem).move_to_element(driver.find_element_by_link_text("專任助理簽到退"));
hover.click().perform();

elem = driver.find_element_by_id("ctl00_ContentPlaceHolder_ddlPlanToday")
Select(elem).select_by_value("500767");

driver.find_element_by_id("ctl00_ContentPlaceHolder_rdSignType_0").click();

elem = driver.find_element_by_id("ctl00_ContentPlaceHolder_txtTodayOther")
elem.clear()
description = u"研究資料整理"
elem.send_keys(description)

driver.find_element_by_id("ctl00_ContentPlaceHolder_btnSignToday").click()

#pause
raw_input()
driver.close()

答案1

将命令括在引号中:

gnome-terminal --command 'bash -c "sleep 30 ; export PATH=$PATH:/home/erik/Downloads/geckodriver_dir ; python ~/Dropbox/BashScripts/fjucheckin.py ; bash"'  

在命令末尾加上“bash”将使终端保持打开状态。

相关内容