<div class="col-xs-3" xpath="1">
<label>Service Duration in mins</label>
<span class="k-widget k-numerictextbox k-overwrite" style="">
<span class="k-numeric-wrap k-state-default">
<input type="text" class="k-formatted-value k-overwrite k-input" title="500" tabindex="0" role="spinbutton" aria-valuemin="0" aria-valuenow="500" aria-disabled="false" style="display: inline-block;">
<input class="k-overwrite k-input" data-val="true" data-val-number="The field DurationInMins must be a number." data-val-required="The DurationInMins field is required." id="DurationInMins" min="0" name="DurationInMins" type="text" value="0" data-role="numerictextbox" role="spinbutton" aria-valuemin="0" style="display: none;" aria-valuenow="500" aria-disabled="false">
<span class="k-select">
<span unselectable="on" class="k-link k-link-increase" aria-label="Increase value" title="Increase value">
<span unselectable="on" class="k-icon k-i-arrow-60-up">
</span>
</span>
<span unselectable="on" class="k-link k-link-decrease" aria-label="Decrease value" title="Decrease value">
<span unselectable="on" class="k-icon k-i-arrow-60-down">
</span>
</span>
</span>
</span>
</span>
<script>
kendo.syncReady(function(){jQuery("#DurationInMins").kendoNumericTextBox({"format":"{0:n0}"});});
</script>
</div>
&#13;
我尝试在旋转按钮(带有增量和减量箭头的文本框)中输入值。 下面的代码抛出一个错误:
Expected condition failed:waiting for element to be clickable.
任何人都可以帮我解决这个错误......
提前致谢...
WebElement ele5=driver.findElement(By.xpath("//input[@id='DurationInMins']"));
JavascriptExecutor executor1=(JavascriptExecutor)driver;
executor1.executeScript("arguments[0].click()",ele5);
WebDriverWait wait1=new WebDriverWait(driver,10);
wait1.until(ExpectedConditions.elementToBeClickable(ele5));
ele5.clear();
ele5.sendKeys("45");
//Thread.sleep(2000);
答案 0 :(得分:2)
根据您共享的 HTML ,所需的元素,即输入字段具有属性 style =“display:none;”。因此,要将字符序列发送到输入字段,您可以使用以下解决方案:
WebElement ele5 = driver.findElement(By.xpath("//input[@class='k-overwrite k-input' and @id='DurationInMins']"));
((JavascriptExecutor)driver).executeScript("arguments[0].removeAttribute('style')", ele5)
ele5.clear();
ele5.sendKeys("45");
答案 1 :(得分:0)
试试这段代码:
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='DurationInMins' and @name='DurationInMins' and contains(@data-val-required,'The DurationInMins field is required')]/preceding-sibling::input")));
WebElement ele5 = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='DurationInMins' and @name='DurationInMins' and contains(@data-val-required,'The DurationInMins field is required')]/preceding-sibling::input")));
ele5.clear();
ele5.sendKeys("45");
如果这是输入字段:
<input class="k-overwrite k-input" data-val="true" data-val-number="The field Capacity must be a number." data-val-required="The Capacity field is required." id="Capacity" min="0" name="Capacity" type="text" value="0" data-role="numerictextbox" role="spinbutton" aria-valuemin="0" style="display: none;" aria-valuenow="0" aria-disabled="false">
然后你必须使用:locator as:
By.id("Capacity")
或
By.name("Capacity")
或强>
By.cssSelector("input[role='spinbutton']")
希望这会有所帮助。
答案 2 :(得分:0)
执行此HTML时,我在UI中得到了这个 inputbox
即只有输入框而不是带有递增和递减箭头的文本框: 进一步检查文本框或输入框我可以使用进入文本框:
WebElement inputField = driver.findElement(By.cssSelector("span.k-state-default input"));
inputField.sendKeys("45");
HTML代码中存在两个输入字段,在尝试检查时,它是第一个可编辑的输入标记,可以用值填充。
如果我对您在问题中提到的UI有了确切的想法,这应该有效 即带有增量和减量箭头的文本框(因为我看不到任何箭头按钮)
因为在运行HTML时,在控制台中它显示kendo not defined并且没有可见的增量/减量按钮。