Reputation: 475
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.
Upvotes: 2
Views: 3817
Reputation: 150
BooBoo's answer is close but you still need to release the shift and enter key, or your input text might get very weird.
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.ENTER).perform()
Refer to this answer
Upvotes: 2
Reputation: 44313
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.
Upvotes: 3
Reputation: 1066
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();
Upvotes: 2