簡體   English   中英

為什么我不能讓 Selenium 使用 Python 3.8 和 Chrome 在我的 WhatsApp Web 中編寫消息?

[英]Why can't I make Selenium write a message in my WhatsApp Web using Python 3.8 and Chrome?

所以我使用這個腳本:

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 

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome('C:/Users/N-Thalpy/Documents/NT/py/chromedriver.exe', chrome_options=chrome_options) 

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


target = '"Batman"'

string = "Python 3.8"

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="_3u328"][@dir="ltr"][@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) 

Chrome 按預期在 web.whatsapp.com 中打開 - 然后打開“蝙蝠俠”聊天。 但是,它什么也沒寫。 我檢查了屬性,甚至試圖更具體地描述它們,但似乎沒有任何效果。 我在沒有沙箱選項的情況下嘗試了它,但仍然沒有。

編輯:我從 py.exe 控制台收到的唯一消息是:

“[13920:4684:0130/154024.795:ERROR:wmi_refresher.cc(129)] 無法添加 Win32_PerfRawData_PerfDisk_PhysicalDisk 枚舉。”

我設法通過以下方式解決它:

  • 下載正確的 chromedriver 版本,因為我使用的是 Chrome 79 並使用 Chrome 80 的驅動程序。
  • 搜索 div 的所有屬性,包括拼寫檢查、contenteditable 和 dir(我不知道這實際上有多相關,但以防萬一)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM