【发布时间】:2020-07-09 19:27:44
【问题描述】:
我为以下代码创建了 .exe。我创建了 /dist 现在尝试执行 .exe 但什么也没发生。请建议如何进行或我做错了什么?是否可以使用 .exe 执行以下代码。请提出建议。
from selenium import webdriver
from time import sleep
import sys
driver = webdriver.Firefox() # To connect to web browser use webdriver imported from selenium
driver.get('https://web.whatsapp.com/')
name = sys.argv[1]
msg = sys.argv[2]
filepath = sys.argv[3]
def whatsapp(name, msg="", filepath=""):
input('Enter anything after scanning QR code')
user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
user.click()
if msg != "":
msg_box = driver.find_element_by_xpath("//*[@id='main']/footer/div[1]/div[2]/div/div[2]")
msg_box.send_keys(msg) # To send message
button = driver.find_element_by_xpath("//*[@id='main']/footer/div[1]/div[3]/button")
button.click() # click send button
if filepath != "":
attachment_box = driver.find_element_by_xpath('//div[@title = "Attach"]')
attachment_box.click() # click attachment icon button
image_box = driver.find_element_by_xpath(
'//input[@accept="image/*,video/mp4,video/3gpp,video/quicktime"]')
image_box.send_keys(filepath) # To send filepath
sleep(3) # use to set delay time of 3 sec. It will first find the image box,
send_button = driver.find_element_by_xpath('//span[@data-testid="send"]')
send_button.click() # click send button
if name != "":
whatsapp(name, msg, filepath) # parameters are passed at run time using sys.argv
if msg != "" and filepath == "":
print("Only message sent successfully")
elif msg == "" and filepath != "":
print("Only attachment sent successfully")
elif msg == "" and filepath == "":
print("Both message and attachment not sent")
else:
print("Both message and attachment sent successfully")
else:
print("name or group name cannot be empty")
【问题讨论】: