0

Yesterday I made this code to send messages by whatsapp. However, I tried many paths to place the message in the messagebox, but nothing seems to be working. Everytime I get the error: Message: unknown error: call function result missing 'value'. I tried all the xpaths (classes) to insert the message, so I think something else is going wrong. When running the code, it opens the web.whatsapp, selects the right person, selects the messagebox, but doesn't place the message in it. Or could it be the version of my driver and chrome which are not corresponding well?

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 datetime
import time

# Replace below path with the absolute path
# to chromedriver in your computer
driver = webdriver.Chrome('insert driver_path')
driver.get("https://web.whatsapp.com/")
WebDriverWait(driver, 10)

name = 'Name Person'

text = 'test from bot'

select_contact = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[role='option'] span[title='{}']".format(name)))).click()
time.sleep(2)

# select_messagebox = driver.find_element_by_css_selector('.pluggable-input-placeholder')
# select_messagebox = driver.find_element_by_class_name('_3FRCZ copyable-text selectable-text')
select_messagebox = driver.find_element_by_xpath('insert x path')
time.sleep(2)
select_messagebox.send_keys(text)
J.Bravo
  • 21
  • 3

1 Answers1

0

Use the below XPath and CSS selector.

XPath:

//*[@id="main"]//div[@class='_3FRCZ copyable-text selectable-text']

CSS selector:

div[class='_3FRCZ copyable-text selectable-text'][data-tab='1']
tripleee
  • 175,061
  • 34
  • 275
  • 318
Dilip Meghwal
  • 632
  • 6
  • 15
  • thank you for your answer, could you please explain it in more detail. I am not sure how to connect the xpath with css selector. Could you provide me with the full line of code? select_messagebox= .............. – J.Bravo Aug 31 '20 at 05:59
  • You can use either XPath or CSS selector. select_messagebox = driver.find_element_by_xpath("//*[@id="main"]//div[@class='_3FRCZ copyable-text selectable-text']") select_messagebox = driver.find_element_by_css_selector("div[class='_3FRCZ copyable-text selectable-text'][data-tab='1']") – Dilip Meghwal Aug 31 '20 at 06:03
  • Unfortunately I still get the same error when using them. So if yours is working fine I think I should have a look at my chrome drive, chrome browser. – J.Bravo Aug 31 '20 at 06:17