0

I have a webapplication which is automated tested currently I have the following HTML content:

<td>
<input name="ctl00$ctl00$BaseRightContent$MainRightContent$FromTextBox" type="text" value="19.06.2019" id="ctl00_ctl00_BaseRightContent_MainRightContent_FromTextBox" class="wideUserInput">
                
<input type="hidden" name="ctl00$ctl00$BaseRightContent$MainRightContent$FromTextBoxMasked_ClientState" id="ctl00_ctl00_BaseRightContent_MainRightContent_FromTextBoxMasked_ClientState">
</td>

For my selenium test I use this workaround:

 if (employmentParam.StartDate != null)
        {
            driver.FindElement(By.Id("ctl00_ctl00_BaseRightContent_MainRightContent_FromTextBox")).Clear();
            driver.FindElement(By.Id("ctl00_ctl00_BaseRightContent_MainRightContent_FromTextBox")).SendKeys(employmentParam.StartDate); //Here is my object (string) Example: employmentParam.StartDate --> 11.02.2100
        }

And currently I have the problem that my selenium inserts only '21.00.2002" instead of the given parameter '11.02.2100' This is how the webelement looks like:

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I feel like this is due to where the text cursor is when Selenium is sending the key strokes. Compare the position of the text cursor when Selenium is "typing" versus when you are typing in the field manually. Is there a difference? – Greg Burghardt Jun 18 '19 at 14:12
  • this is hard to tell since i don't know how the selenium framework is sending the keys if you debug the test you don't see a text cursor. – RuntimeError Jun 18 '19 at 14:32
  • I think we can just try sending the date in plain format - 11022100. Most of the date fields auto correct the input. Remember when we manually enter it, we don't usually type "." between the values. – Sureshmani Kalirajan Jun 18 '19 at 15:06

2 Answers2

0

The desired element is a dynamic element so you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies as solutions:

  • CssSelector:

    var element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.wideUserInput[id$='_BaseRightContent_MainRightContent_FromTextBox'][name$='FromTextBox']"))).Click();
    element.Click();
    element.Clear();
    element.SendKeys(employmentParam.StartDate);
    
  • XPath:

    var element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='wideUserInput' and contains(@id, '_BaseRightContent_MainRightContent_FromTextBox')][contains(@name, 'FromTextBox')]"))).Click();
    element.Click();
    element.Clear();
    element.SendKeys(employmentParam.StartDate);
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • thanks for your answer. my selenium class does not have the method "ElementToBeClickable" (ExpectedConditions does not contain a definition for ElementToBeClickable) --> to old selenium version? don't rly want to upgrade due to unkown changes to the other tests – RuntimeError Jun 18 '19 at 14:31
0

Here is the solution for the problem:

               IWebElement wb = driver.FindElement(By.CssSelector("input.wideUserInput[id$='_BaseRightContent_MainRightContent_FromTextBox'][name$='FromTextBox']"));
                IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
                jse.ExecuteScript($"arguments[0].value='{employmentParam.StartDate}';", wb);
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92