How can I press ENTER key with the execute script in selenium python

+2 votes

I'm not able to press ENTER key when executing the script. Below is my code:

f=driver.find_element_by_css_selector("textarea._bilrf")
(driver.execute_script("arguments[0].value = arguments[1]", f, "Hi!"))

The word "Hi!" is sent to the element. But, not able to press ENTER to send it. Also, send_keys() and submit() don't work in my code. This is the url where i'm working: https://www.instagram.com/p/BgdhsyvgWCi/?taken-by=asarokh

Mar 28, 2018 in Selenium by code_ninja
• 6,290 points
26,551 views

2 answers to this question.

+3 votes

The below code containing Keys.ENTER might just work for you:

from selenium.webdriver.common.keys import Keys
driver.find_element_by_xpath("""//*[@id="react-root"]/section/main/div/div/article/div[2]/section[1]/a[2]/span""").click()
driver.find_element_by_css_selector("textarea._bilrf").send_keys("Hi!", Keys.ENTER)
answered Mar 28, 2018 by nsv999
• 5,500 points
Bro, cant thank you more. I was stuck with this Enter Key and you saved my life.
Haha. Your welcome :)
How I can open the link in a new tab using the click and control command together?
You can hold down the control button or the command key – to open a link in a new tab. You can also click on a link and hold down the mouse without releasing, dragging the link to the browser's tab bar to open it in a new tab.

Or add this html code:
<a href="http://www.edureka.co" target="_blank">Edureka home</a>
Hi Niroj,

I am talking about how to open the link with click event in a new tab using selenium not manually.

Your help will be highly appreciated.

Thanks,
0 votes
import pyautogui

pyautogui.hotkey('enter')
answered Mar 26, 2019 by anonymous

Related Questions In Selenium

0 votes
1 answer

How can I write test scripts in Selenium with python?

Hey Khushi, writing test scripts in Selenium ...READ MORE

answered May 9, 2019 in Selenium by Anvi
• 14,150 points
634 views
0 votes
1 answer
+1 vote
2 answers

How can I delete an element in Selenium using Python?

You can directly delete the node using ...READ MORE

answered Sep 14, 2019 in Selenium by tonystark
• 500 points
18,708 views
0 votes
1 answer

How can I add Cucumber Jar files in Eclipse to use with Selenium Webdriver?

Hey Eshan, follow these steps to add ...READ MORE

answered May 23, 2019 in Selenium by Abha
• 28,140 points
5,552 views
+1 vote
2 answers

Python with Selenium issue: “Chrome is being controlled by automated test software”

from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.add_experimental_option("useAutomationExtension", False) chrome_options.add_experimental_option("excludeSwitches",["enable-automation"]) driver ...READ MORE

answered Apr 20, 2020 in Selenium by Manoj
14,817 views
–1 vote
1 answer

Selenium XPath error:- Element not found

The reason for Element not found exception ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
19,720 views
0 votes
1 answer

Need to download a file using Selenium

Pretty simple...Find the element or link using ...READ MORE

answered Mar 30, 2018 in Selenium by nsv999
• 5,500 points
3,170 views
0 votes
1 answer

How do i change the location where my file gets downloaded in Selenium Webdriver and firefox driver?

There are a couple of errors there. ...READ MORE

answered Apr 13, 2018 in Selenium by nsv999
• 5,500 points
5,825 views
0 votes
6 answers

How to specify "ENTER" button functionality in Selenium WebDriver code?

using OpenQA.Selenium.Interactions; Actions builder = new Actions(driver); ...READ MORE

answered Feb 13, 2019 in Selenium by anonymous
94,460 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP