- I also had same issue,
- In the WhatsApp web "\n" works as a key.
- For breaking a line in WhatsApp web you have to use its short keys to break the line.
- Short keys for line break in WhatsApp web are : SHIFT+ENTER
- But if we use it with code then it will hold the 'SHIFT' key during the whole execution. So the text capitalization is going to be change.
- For prevention from capitalization changes you have to send 'SHIFT' key once again to release the 'SHIFT' key.
So the keys which are going to send by code will be : SHIFT+ENTER+SHIFT
You can use any suitable way which will work for you better.
# Necessary libraries
import pyautogui as pg
import webbrowser as web
import time
from selenium.webdriver.common.keys import Keys
#You have to install selenium for keys or can choose any other library.
message = "Dear Student," + (Keys.SHIFT)+(Keys.ENTER)+(Keys.SHIFT) + "Please send your report" + (Keys.SHIFT)+(Keys.ENTER)+(Keys.SHIFT) + "Thank you for your attention"
number = 'XX_XXXXXXXXX'
web.open("https://web.whatsapp.com/send?phone="+number+"&text="+message)
time.sleep(12) # wait for the page to load
pg.click(1335, 690) # click on the submit button location
Maybe following method will also work for you.
# Necessary libraries
import pyautogui as pg
import webbrowser as web
import time
message = """Dear Student, \
Please send your report \
Thank you for your attention"""
# In the above just use '\' which is used for concatenation.
# But you have to give extra spaces as I have mentioned.
# because '\' will add only 2 tab spaces in the message during writing.
number = 'XX_XXXXXXXXX'
web.open("https://web.whatsapp.com/send?phone="+number+"&text="+message)
time.sleep(12) # wait for the page to load
pg.click(1335, 690) # click on the submit button location
Update : Must use this following way
- The above messages looks too complicated to type.
- So you can use that in following simple way by assigning the keys in a variable to use simply
import pyautogui as pg
import webbrowser as web
import time
from selenium.webdriver.common.keys import Keys
#You have to install selenium for keys or can choose any other library which be suitable for you.
br = (Keys.SHIFT)+(Keys.ENTER)+(Keys.SHIFT)
message = "Dear Student," + br + "Please send your report" + br + "Thank you for your attention"
number = 'XX_XXXXXXXXX'
web.open("https://web.whatsapp.com/send?phone="+number+"&text="+message)
time.sleep(12) # wait for the page to load
pg.click(1335, 690) # click on the submit button location
Or can try using f or .format string to make it simple.
import pyautogui as pg
import webbrowser as web
import time
from selenium.webdriver.common.keys import Keys
#You have to install selenium for keys or can choose any other library which be suitable for you.
br = (Keys.SHIFT)+(Keys.ENTER)+(Keys.SHIFT)
message = f"Dear Student,{br}Please send your report{br}Thank you for your attention"
####################### Or #########################
# message = "Dear Student,{0}Please send your report{0}Thank you for your attention".format(br)
number = 'XX_XXXXXXXXX'
web.open("https://web.whatsapp.com/send?phone="+number+"&text="+message)
time.sleep(12) # wait for the page to load
pg.click(1335, 690) # click on the submit button location
in message ? – Gerard Rozsavolgyi Mar 06 '21 at 16:08