2017-10-17 79 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)