我正在尝试在预先设定的时间内自动化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
你能告诉我为什么在位置正确的情况下发生这种情况吗?
你的错误信息截图(不要这样做!发布文本!)显示的源代码与您发布的源代码不同。在
您必须转义路径中的}。在
\
,因此C:\Users
应该是{相关问题 更多 >
编程相关推荐