Ramji Iyer
Ramji Iyer

Reputation: 11

Is it possible to type text from a specific cursor location?

Given -> Selenium version 1 and Form Field Type -> Textbox.

What I am trying to do is this -> Type string M1 and then send carriage return and then type string M2 into the textbox area.

Upvotes: 1

Views: 6004

Answers (2)

ishandutta2007
ishandutta2007

Reputation: 18274

If driver is your web driver instance here is how the code in python look like, switch_to.active_element is what you need to take your send_key inputs for the element under the cursor (assuming you are familiar with the more common way of finding by a selector or xpath or id and then using send_to for that)

active_ele = driver.switch_to.active_element
active_ele.send_keys("bla bla message")

Upvotes: 2

Nashibukasan
Nashibukasan

Reputation: 2028

In Selenium there is a call from Actions(driver).SendKeys where you can can send keys without specifying an element. Use this to SendKeys to your Textbox element and then a separate call to just send a Selenium.Enter character.

EG. In C#, where _myDriver is your WebDriver.

(new Actions(_myDriver)).SendKeys(OpenQA.Selenium.Keys.Enter).Perform();

Alternatively, if you are on a windows machine you can use Windows Send Keys and send a Enter keystroke then.

Upvotes: 1

Related Questions