from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium import webdriver
import os
#Defining path, driver
PATH = "C:\\Program Files (x86)\\chromedriver.exe"
driver = webdriver.Chrome(PATH)
def site(website):
"""
website to visit
"""
driver.get(website)
def login(user, passwd):
"""
typing user data and login into the website of your choice.
Note: change id of the driver according to your site you are login into.
"""
username = driver.find_element_by_id("user")
password = driver.find_element_by_id("password")
submit = driver.find_element_by_id("submitButton")
username.send_keys(user)
password.send_keys(passwd)
submit.send_keys(Keys.RETURN)
site("https://website-login-page/")
login(os.environ.get('user'),os.environ.get('pass') )
try:
#waiting until an element is clickable and then clicking it.
element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "something")))
element.click()
except Exception as e:
driver.quit()
我已经创建了这个python文件以自动登录网站,并且以python执行时可以正常工作,但是当我使用“ pyinstaller --onefile --noconsole file.py”创建其可执行文件时,它成功创建了可执行文件,但是当我运行该可执行文件,显示执行失败。 谁能帮我解决这个问题吗?