0

My goal is to write:

Hello
World!

on facebook messenger but I can only achieve:

Hello

World!

This is my code:

driver.get('https://www.facebook.com/messages/t/[RECIPIENT]')
time.sleep(1)
MessageBox = driver.find_element_by_class_name('_5rpu')
Message = 'Hello\nWorld!'
NewLine = ActionChains(driver)
Lines = Message.split('\n')
for x in range(0,len(Lines)):
    print(x)
    print(Lines[x])
    MessageBox.send_keys(Lines[x])
    NewLine.key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.ENTER).key_up(Keys.SHIFT)
    if x != len(Lines)-1:
        NewLine.perform()
        print('NEW LINE')  

The output is:

0
Hello
NEW LINE
1
World!

Seeing as NEW LINE is printed only once, it seems the ActionChain is only called once yet creates two lines.

1 Answers1

0
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
friends.browser.find_element(By.XPATH, '//*[@class="xat24cr           
xdj266r"]').send_keys(message)
ActionChains(friends.browser).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.ENTER).perform()
    try :
        friends.browser.find_element(By.XPATH, '//*[@class="xat24cr xdj266r"]').send_keys(message)
    except:
        friends.browser.find_element(By.XPATH, '//*[@class="xat24cr xdj266r xdpxx8g"]').send_keys(message)
BMBL
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – NameVergessen Dec 21 '22 at 10:09