Selenium не может отправлять ключи в текстовое поле datetime - PullRequest
0 голосов
/ 18 июня 2019

У меня есть веб-приложение, которое в настоящее время проверено автоматически. У меня есть следующий HTML-контент:

<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>

Для теста на селен я использую этот обходной путь:

 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
        }

И в настоящее время у меня проблема в том, что мой селен вставляет только «21,00.2002» вместо заданного параметра «11 .02.2100». Вот как выглядит webelement:

enter image description here

Ответы [ 2 ]

0 голосов
/ 18 июня 2019

Вот решение проблемы:

               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);
0 голосов
/ 18 июня 2019

Требуемый элемент является динамическим, поэтому вам нужно ввести WebDriverWait для желаемого ElementToBeClickable(), и вы можете использовать любую из следующих Стратегий локатора в качестве решения:

  • 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);
    
...