2017-10-17 115 views
0

在WhatsApp的短信自動發送的郵件我的代碼是(從geeksforgeeks研究):錯誤使用python

#!/usr/bin/python 
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('C:\webdriver\chromedriver.exe') 
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 = "Rahul Mehta" 
# Replace the below string with your own message 
string = "Hi" 
y_arg = '//*[@id="side"]/div[2]/div/label/input' 
input_y = wait.until(EC.presence_of_element_located((By.XPATH, y_arg))) 
input_y.send_keys(target + Keys.ENTER) 
inp_xpath = '//*[@id="main"]/footer/div[1]/div[1]/div/div[2]' 
input_box = wait.until(EC.presence_of_element_located((By.XPATH,inp_xpath))) 
for i in range(2): 
    input_box.send_keys(string + Keys.ENTER) 
    time.sleep(1) 

我得到的錯誤爲:

[1436:4360:1017/202620.286:ERROR:shader_disk_cache.cc(237)] Failed to create 
shader cache entry: -2 

我得到命令,在相同的重複錯誤當我增加範圍時提示。瀏覽器被打開,然後甚至搜索我的朋友的名字,但最終它不會發送消息。請幫助我。我幾乎浪費了一整天的時間,但對於如何繼續進一步沒有線索:(

+0

你介意複製/粘貼錯誤信息爲文本嗎?請參考[阻止代碼和/或錯誤的屏幕截圖](https://meta.stackoverflow.com/questions/303812 /令人沮喪 - 代碼和錯誤的屏幕截圖) –

+0

Pos sple重複[Python Selenium - 通過其關於緩存的Css選擇器問題查找元素](https://stackoverflow.com/questions/46393818/python-selenium-locating-an-element-by-its-css-selector-issue -about-caching) –

+0

我添加了錯誤信息。 –

回答

0

我也面臨同樣的問題,我推斷出的結論是,實際上,每個新版本whatsapp改變了編寫代碼的方式來自動化HTML代碼,你必須檢查HTML的新語法。現在我想到的是這個我沒有任何想法,直到這段代碼有效,但現在,它工作正常。

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 


driver = webdriver.Chrome(r'F:/chrome driver/chromedriver.exe') 

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

target = '"friend\'s name"' 

string = "your message" 

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="pluggable-input-body copyable-text selectable-text"][@dir="auto"][@data-tab="1"]' 
input_box = wait.until(EC.presence_of_element_located((
    By.XPATH, inp_xpath))) 

for i in range(10): 
    input_box.send_keys(string + Keys.ENTER)