【发布时间】:2021-04-05 00:49:52
【问题描述】:
我尝试使用 selenium 在 whatsapp 中向我的朋友发送消息。我下载了适用于 windows 的最新版本的 chromedriver,当我运行代码时,whatsapp web 已打开但消息未发送。这是我的代码和我遇到的错误:-
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(executable_path=r'D:\Whatsapp Automation\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 = "Friend's name"
# Replace the below string with your own message
string = "Hii"
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)
这是我得到的调试文件
[1228/125305.696:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights. (0xc0000022)
[1228/125305.696:ERROR:exception_snapshot_win.cc(99)] thread ID 8952 not found in process
[1228/125305.742:ERROR:process_reader_win.cc(151)] SuspendThread: Access is denied. (0x5)
[1228/125305.758:ERROR:process_reader_win.cc(151)] SuspendThread: Access is denied. (0x5)
[1228/125305.758:ERROR:process_reader_win.cc(151)] SuspendThread: Access is denied. (0x5)
[1228/125305.758:ERROR:process_reader_win.cc(151)] SuspendThread: Access is denied. (0x5)
[1228/125305.758:ERROR:process_reader_win.cc(151)] SuspendThread: Access is denied. (0x5)
[1228/125305.758:ERROR:process_reader_win.cc(151)] SuspendThread: Access is denied. (0x5)
[1228/125305.758:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights. (0xc0000022)
[1228/125305.758:ERROR:exception_snapshot_win.cc(99)] thread ID 10128 not found in process
我从https://chromedriver.storage.googleapis.com/index.html?path=87.0.4280.88/下载了chromedriver
【问题讨论】:
标签: python selenium selenium-webdriver selenium-chromedriver whatsapp