Python Bot for replying hi on Whatsapp
message-in
class is really useful here, just list all elements of this class and read the content of the last element with this class.
def send_message(driver, message): # Send a message if driver has a conversation in focus message_box = driver.find_element_by_xpath('//div[@class="_3uMse"]')` message_box.send_keys('Hey, I am your whatsapp bot') message_box = driver.find_element_by_xpath('//button[@class="_1U1xa"]') message_box.click() def find_hi_and_reply(driver): # If last received message is "hi", replies "hi back!!" messages_in = driver.find_elements_by_class_name('message-in') last_message = messages_in[-1] last_msg_content = last_message.find_element_by_class_name('copyable-text').text if last_msg_content == 'hi': send_message(driver, 'hi back!!')