How can I get selenium to get a keyboard press of shift + enter at the same time using python?

Viewed 1565

I've made a whatsapp bot and a web scraper to get coronavirus cases and I want to send each data on a newline. Eg

Cases: x

Deaths: y

Recovered: z

But as im using whatsapp, /n doesn't work and would send each individual line. I've also tried ActionChains but that didn't work either. Any idea on how I can get a key combination for Shift + Enter? Thanks.

2 Answers

For Python:

from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains

ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER).perform()

However, I could only get the above to work for Edge, not for Firefox nor Chrome.

This is what you needed. Corresponding Java Implementation...

Actions actions = new Actions(driver);
// Press SHIFT + ENTER            
actions.keyDown(Keys.SHIFT)
        .sendKeys(Keys.RETURN)
        .build()
        .perform();
Related