none
object.SendKeys result in IE Vs Chrome differs for an edit box with default value

    Question

  • Hi,

    I have an edit box in the page which is blank by default. However on click, it sets a value of 0.00. 

    Using my selenium script I am setting a value to the edit box as shown below:

    editbox.SendKeys("2.50"); 

    In case of IE it works perfectly fine. The output in the editbox is 2.50 as expected. 

    In case of Chrome, the desired text gets appended to 0.00. The output in the editbox looks something like 0.002.50.

    I could think of multiple fixes for this, but I would like to know the best possible fix for this. 

    Also could you please tell me what could be the reason that the automation script is behaving differently in the 2 browsers?

    Monday, October 10, 2016 1:02 PM

Answers

  • Below is the solution I implemented for my problem. 

    as an input parameter, there is a case where value of 'text' is sent as ("2.5" + Keys.Tab); So the below solution matched my problem the best. Hope it is useful for someone.  

    private static void SetText(this IWebElement element, string text)
            {
                Actions clearAndType = new Actions(FastDriver.WebDriver);
                try
                {
                    clearAndType.SendKeys(element, Keys.Home).KeyDown(Keys.Shift).SendKeys(Keys.End).KeyUp(Keys.Shift).SendKeys(Keys.Delete).SendKeys(text).Build().Perform();              
                }
                catch
                {
                    throw new Exception("Text could not be set");
                }
            }

    Thanks & Regards

    Sandeep P Raju

    • Marked as answer by SandeepPRaju Friday, October 14, 2016 12:29 PM
    Friday, October 14, 2016 12:29 PM

All replies

  • Do you have a code that moves the focus to the edit box, activating it? Probably the value “0.00” should become selected (highlighted). This will ensure that the typed text replaces the old one.

    Monday, October 10, 2016 5:22 PM
  • Hi SandeepPRaju,

    Thanks for Viorel_'s help. Please confirm the edit box content has been clean or the content has been selected.

    According to your description, you are running Coded UI Test with Selenium script to test the edit box. Do you use the Selenium Components for Coded UI Cross Test browser Testing?

    I'm using following Coded UI script to find a edit box in Chrome and using the Keyboard.SendKeys() to input "2.50". Everything is fine. If your script is different with mine, please share your code snippet here. I will test your code to check whether there has any issue in your code.

            [TestMethod]
            public void CodedUITestForChrome()
            {
                BrowserWindow.CurrentBrowser = "Chrome";
                BrowserWindow window = BrowserWindow.Launch("http://google.com");
    
                UITestControl edit = new UITestControl(window);
                edit.SearchProperties.Add("ControlType", "Edit");
                edit.SearchProperties.Add("Name", "EditBoxName");
    
                Mouse.DoubleClick(edit);
    
                Keyboard.SendKeys("2.50");
    
                Playback.Wait(10000);
    
            }

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 11, 2016 7:12 AM
    Moderator
  • Below is the solution I implemented for my problem. 

    as an input parameter, there is a case where value of 'text' is sent as ("2.5" + Keys.Tab); So the below solution matched my problem the best. Hope it is useful for someone.  

    private static void SetText(this IWebElement element, string text)
            {
                Actions clearAndType = new Actions(FastDriver.WebDriver);
                try
                {
                    clearAndType.SendKeys(element, Keys.Home).KeyDown(Keys.Shift).SendKeys(Keys.End).KeyUp(Keys.Shift).SendKeys(Keys.Delete).SendKeys(text).Build().Perform();              
                }
                catch
                {
                    throw new Exception("Text could not be set");
                }
            }

    Thanks & Regards

    Sandeep P Raju

    • Marked as answer by SandeepPRaju Friday, October 14, 2016 12:29 PM
    Friday, October 14, 2016 12:29 PM