1

Selenium c# when entering data in a Textbox for My Test Website the the cursor position is set to the Middle and the data entered is like for e.g. 3421 instead of the correct Order of 1234.

Can anyone suggest a good way as to how to handle this?

I have tried to Use pressing the HOME key button but it did not work.

undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
nika65
  • 31
  • 1
  • 5
  • 2
    Welcome to SO, Please read https://stackoverflow.com/help/mcve and provide what you tried so far? – Prasad Telkikar Aug 23 '18 at 06:31
  • Please post your code – Jayendran Aug 23 '18 at 06:44
  • tried doing it with to enter value with JS it worked in most cases but still in some cases it enters in wrong order ,Pressing Home key to move the cursor to first position before entering value didn't work at all, Clear+ sendKeys did not work, is there Any other way to shift the cursor Position or set value – nika65 Aug 23 '18 at 09:48

1 Answers1

0

It would be tough to predict the actual issue behind the non perseverance of the sequential order of the character sequence sent through SendKeys() method in absence of the relevant HTML.

However, in case the AUT (Application Under Test) is JavaScript, Angular or ReactJS based, as per best practices you need to induce WebDriverWait for the desired element to be clickable, then you need to invoke Clear() method and finally invoke SendKeys() method as follows:

  • C#:

    IWebElement textBoxElement = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("xpath_of_HOME_key_button")));
    textBoxElement.Click();
    textBoxElement.Clear();
    textBoxElement.SendKeys("1234");
    
undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
  • Tried this way but seem to be working in few cases , Is there some other way to make sure that value is always set Properly as most of our Scenarios are dependent on this Textbox being Entered Properly. – nika65 Aug 23 '18 at 09:53
  • @nika65 Checkout my updated answer and let me know the status. – undetected Selenium Aug 23 '18 at 10:15