driver.findelement(By.Id("Text"+Keys.enter));
This piece of code is finding the element on the page with an ID of "text" + Keys.enter
(whatever Keys.enter
translates to in the compiler).
This line of code Does Not enter text into the text attribute of the element. You need to first Find the element, then send the value to the element, something like this
var element = driver.FindElement(By.Id("ElementID"));
element.SendKeys("text" + Keys.enter);
Or you can do it all in one line without assigning the element to a variable.
driver.FindElement(By.Id("ElementID")).SendKeys("text" + Keys.enter);
You can do it like this the first time. If you want to replace what is in the textbox then you need to do something different.
When I want to replace the text I could figure out how to delete what I know is in there, but that could turn ugly, so instead I make use of the Driver's ExecuteScript
method like this
var element = driver.FindElement(By.Id("ElementID"));
var text = "text you want in your element's value attribute";
driver.ExecuteScript("arguments[0].setAttribute('value', arguments[1])", element, text);
The FindElement
method just returns an IWebElement
based on the search parameters that you give it.
I don't think that you want to find the element with the ID of "text" + Keys.enter
, Keys.enter
returns a key code for the enter key, not a function or an action.
You are not grabbing the same element. you are giving each command a different ID so they are looking for two different elements.
the first line
driver.findelement(By.Id("Text"+Keys.enter));
has a different ID than the second line
driver.findelement(By.id("Text2"+Keys.enter));
so when you put these into a variable they are actually two different elements
var firstElement = driver.FindElement(By.Id("id1"));
var secondElement = driver.FindElement(By.Id("id2"));
var areElementsTheSame = firstElement == secondElement;
areElementsTheSame
is false.
you haven't put anything into any text field on the page when you run either line of code that you have posted, that is a different operation.