带有Kendo UI的Selenium [英] Selenium with Kendo UI
问题描述
我们将Kendo UI用于按钮和文本框.它引起硒的问题.如果用户手动测试,则步骤为>>,它们将鼠标拖到文本框上,文本框突出显示,用户单击该文本框.然后光标开始显示,用户可以键入.
We are using Kendo UI for our buttons and textbox. It is causing issues for selenium. If user test manually then steps are>> they drag their mouse over to the text box, the text box is highlighted and the user clicks on the textbox. Then the cursor starts to show up and the user can type in.
对于硒,"driver.findElement"可以找到文本框,但无法获取光标.我也尝试了textbox.click和鼠标事件,
As for selenium 'driver.findElement' is able to find the textbox but not able to get a cursor. I tried textbox.click and mouse event too,
推荐答案
尝试使用executeScript
方法设置元素的值:
Try to set value of element using the executeScript
method:
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('elementID').setAttribute('value', 'yourValue')");
但是正如@JeffC已经提到的那样,这不是一个清晰"的解决方案.您可以在下面看到更好的一个.
But as @JeffC already mentioned, it is not a "clear" solution. The better one you can see below.
您可以在此处中看到该文本框的工作方式如下:
As you can see here the text box is working as following:
- 您必须通过此xPath单击第一个输入:
//ul[@id = 'fieldlist']/li[1]/label/span/span/input[1]
是此输入字段:
- 在单击第一个输入之前,单击第二个输入
有display:none
.现在它具有display:inline-block
,因此我们可以通过此xPath //ul[@id = 'fieldlist']/li[1]/label/span/span/input[2]
在此(第二个)元素上执行sendKeys()
动作.
had display:none
. And now it has display:inline-block
, so we can perform sendKeys()
action on this(second) element via this xPath //ul[@id = 'fieldlist']/li[1]/label/span/span/input[2]
.
您可以根据自己的情况做同样的事情.
The same thing you can do in your case.
代码中的PS就像这样:
PS in the code it would be like this:
WebElement firstInput = driver.findElement(By.xpath("//ul[@id = 'fieldlist']/li[1]/label/span/span/input[1]"));
firstInput.click();
new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//ul[@id = 'fieldlist']/li[1]/label/span/span/input[2]")); // waits until second input becomes visible
WebElement secondInput = driver.findElement(By.xpath("//ul[@id = 'fieldlist']/li[1]/label/span/span/input[2]"));
secondInput.sendKeys("55");
这篇关于带有Kendo UI的Selenium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!