进程在python中以退出代码1错误结束

时间:2017-04-27 08:05:32

标签: python automation pycharm selenium-chromedriver

我试图在预先设定的时间内自动化whatsapp消息。我用pycharm ide。

参见示例代码

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

# Replace below path with the absolute path
# to chromedriver in your computer
driver = webdriver.Chrome('/home/saket/Downloads/chromedriver')

driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 600)

# Replace 'Friend's Name' with the name of your friend 
# or the name of a group 
target = '"Friend\'s Name"'

# Replace the below string with your own message
string = "Message sent using Python!!!"

x_arg = '//span[contains(@title,' + target + ')]'
group_title = wait.until(EC.presence_of_element_located((
    By.XPATH, x_arg)))
group_title.click()
inp_xpath = '//div[@class="input"][@dir="auto"][@data-tab="1"]'
input_box = wait.until(EC.presence_of_element_located((
    By.XPATH, inp_xpath)))
for i in range(100):
    input_box.send_keys(string + Keys.ENTER)
    time.sleep(1)

我从here

获取了此代码

我将计算机中的chromedriver路径替换为C:\ Users \ public \ chromedriver.exe但是点击了运行按钮后显示路径错误。

这是截图。

chrome driver location error on PC

你能告诉我为什么会发生这种情况但位置是否正确?

1 个答案:

答案 0 :(得分:1)

您错误消息的屏幕截图(不要这样做!发布文字!)显示的源代码与您发布的内容不同。

您必须逃避路径中的\,因此C:\Users应为C:\\Users