我的代码是(从geeksforgeeks学习):
#!/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 :(得分:1)
我也面临同样的问题,我推断出的结论是,实际上,对于每个新版本,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)