Selenium sendkey sending unspecified text in the textbox - C#

Asked

Viewed 312 times

-1

When using the Sendkeys function in Selenium, the value sent to the textbox is dropped.

This happens for both Chrome and Firefox.

Ex.: I’m sending the value 123456789 to the textbox field and it’s coming 234567891.

var campo = driver.FindElement(By.Id("txtNumero")); campo.Clear(); campo.SendKeys("123456789");

2 answers

0


At Paulo’s suggestion, I added a click before sending the data. For some situations, this solved and for others the alternative was to use the sending of data via javascript:

var valor_enviado = "123456789"
var campo = driver.FindElement(By.Id("nome_do_campo"))
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("arguments[0].value='" + valor_enviado + "';", campo);

0

Try to put before the Sendkeys . Click();

field. Click();

field. Clear();

Sendkeys field("123456789");

It may be that the field is not yet selected and so should lose the first character.

I hope I’ve helped

  • Paulo, partially solved. For some sites, this solution worked, but for others, it did not.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.