I am new to python, want to add new line when user enters \n.
There are 2 cases in the first (Case 1) the inputtext
is already defined and after every \n
a new line is added. And in the second case when I take the input from the user (Case 2), it prints \n
i.e., a new line is not added.
Case 1:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
driver.get("http://127.0.0.1:5500/testh.html")
inputtext = 'asjbjd,hashd\nakshdas\nakshdlhsd\n\n\nkadks\n\n\n0932492348'
elem = driver.find_element(By.XPATH, '/html/body/form/textarea')
for part in inputtext.split('\n'):
elem.send_keys(part)
ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.ENTER).perform()
Case 2:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
inputtext = input('share the input')
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
driver.get("http://127.0.0.1:5500/testh.html")
elem = driver.find_element(By.XPATH, '/html/body/form/textarea')
for part in inputtext.split('\n'):
elem.send_keys(part)
ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.ENTER).perform()
Can someone help me with this.