问题
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.
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,
回答1:
Try to set value of element using the executeScript
method:
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('elementID').setAttribute('value', 'yourValue')");
EDIT:
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:
- you have to click on the first input via this xPath:
//ul[@id = 'fieldlist']/li[1]/label/span/span/input[1]
it is this input field:
- Before clicking on first input the second input
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 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");
来源:https://stackoverflow.com/questions/50764183/selenium-with-kendo-ui