我在启动应用程序中添加一个项目如下: 编辑启动程序
为了您的方便,我在这里重复命令:
gnome-terminal --command "sleep 30;export PATH=$PATH:/home/erik/Downloads/geckodriver_dir;python ~/Dropbox/BashScripts/fjucheckin.py"
预计在我进入办公室打开笔记本电脑后,打开一个gnome-terminal,然后运行python脚本fjucheckin.py
打开一个Firefox窗口,然后自动代我签到,然后等我按键关闭 Firefox 窗口。但事实证明,没有出现 gnome-terminal 或 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()
用引号将您的命令括起来:
在命令末尾添加“bash”将使终端保持打开状态。