B
B
Bl4ckm45k2020-10-30 22:33:04
Python
Bl4ckm45k, 2020-10-30 22:33:04

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() #Кликнуть на кнопку отправки


Under Windows, the message looks like this:
"Hi, {username}!
Your number: {number}."

And running the same script in Ubuntu 20.04 gives this:
"Hi,
{username}! Your
number
is [number][-1:]"

Tell me what I'm doing wrong, thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Yakushenko, 2020-10-30
@kshnkvn

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 question

Ask a Question

731 491 924 answers to any question