Answer the question
In order to leave comments, you need to log in
Selenium in ubuntu how to wrap lines correctly?
Hello! There is a code to send messages to whatsapp that works fine on windows
msg1 = f"Привет, {name}!" #Первая строка сообщения
msg2 = f"Твой номер #{numb}." #Вторая строка
msg_box = driver.find_element_by_xpath("//*[@id='main']/footer/div[1]/div[2]/div/div[2]") #Поиск текстового окна
msg_box.send_keys(msg1) # Первая строка сообщения
ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER).perform() #Зажать Shift+Enter, перевести строку
ActionChains(driver)key_up(Keys.SHIFT).key_up(Keys.ENTER).perform() #Отжать клавиши
msg_box.send_keys(msg2) #Вторая строка сообщения
ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER).perform()
ActionChains(driver).key_up(Keys.SHIFT).key_up(Keys.ENTER).perform()
driver.find_element_by_xpath("//*[@id='main']/footer/div[1]/div[3]/button").click() #Кликнуть на кнопку отправки
Answer the question
In order to leave comments, you need to log in
Somehow it looks strange, you have Shift + Enter pressed for some time, perhaps from the Linux side it is somehow not processed in the same way. Try to translate a string in one action:
import time
msg1 = f"Привет, {name}!" #Первая строка сообщения
msg2 = f"Твой номер #{numb}." #Вторая строка
msg_box = driver.find_element_by_xpath("//*[@id='main']/footer/div[1]/div[2]/div/div[2]")
msg_box.click()
for s in (msg1, msg2):
for c in s:
msg_box.send_keys(s)
time.sleep(0.2)
ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.ENTER).perform()
ActionChains(driver).send_keys(Keys.RETURN).perform()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question