【问题标题】:kendo combobox with selenium Java带有硒 Java 的剑道组合框
【发布时间】:2019-11-01 16:25:45
【问题描述】:

我正在尝试使用 selenium 自动化 Kendro UI 应用程序。我不确定 selenium 是否适合用于 Kendro UI 应用程序。

您能帮我选择一个带有 selenium 的 Kendro UI Combobox 下拉值吗?

我尝试了多种方法,但到目前为止都没有奏效。

我的代码: 我单击下拉菜单中的箭头并等待几秒钟,然后尝试选择一个值。 但问题是,由于某种原因,下拉它在 10 次中有 4 次起作用。所以这不是一个正确的解决方案

WebElement firstDropDown = driver.findElement(By.xpath("//innova-combobox-input[@name='LHSCID']//span[@class='k-select']"));

firstDropDown.click();
new WebDriverWait(driver,50).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(),'LHSC 1000 Technician Site A')]")))

driver.findElement(By.xpath("//span[contains(text(),'LHSC 1000 Technician Site A')]")).isDisplayed();
driver.findElement(By.xpath("//span[contains(text(),'LHSC 1000 Technician Site A')]")).click();

下面是下拉页面的 HTML 代码:

<input name="{{::$ctrl.name}}_input" class="k-input innova-invalid" type="text" autocomplete="off" title="" role="combobox" aria-expanded="false" style="" tabindex="0" aria-disabled="false" aria-autocomplete="list" aria-owns="" aria-busy="false" aria-activedescendant="d5147cf1-35ff-4160-ad0f-c164916f59c7" xpath="1">

以及下拉值

<ul unselectable="on" class="k-list k-reset" tabindex="-1" aria-hidden="true" aria-live="polite" data-role="staticlist" role="listbox" style="" xpath="1">
<li tabindex="-1" role="option" unselectable="on" class="k-item k-state-focused" data-offset-index="0" id="d5147cf1-35ff-4160-ad0f-c164916f59c7" style=""></li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="1">
<span ng-bind="dataItem.Display"></span>
</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="2" style=""></li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="3"></li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="4"></li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="5"></li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="6"></li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="7"></li>
<li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="8"></li>
</ul>

【问题讨论】:

标签: java selenium kendo-ui


【解决方案1】:

你是对的。由于这是一个复杂的应用程序,因此我们可以尝试多种方法来解决此问题。

一个相当简单的尝试就是 clear 和 sendKeys。

WebElement firstDropDown = driver.findElement(By.xpath("(//*[text() = 'T-shirt Fabric']//following::input)[1]"));
firstDropDown.click();
firstDropDown.clear();
firstDropDown.sendKeys("Cotton");

如果您遇到 StaleElementException,请尝试在每一行中使用 findElement。

driver.findElement(By.xpath("(//*[text() = 'T-shirt Fabric']//following::input)[1]")).click();
driver.findElement(By.xpath("(//*[text() = 'T-shirt Fabric']//following::input)[1]")).clear();
driver.findElement(By.xpath("(//*[text() = 'T-shirt Fabric']//following::input)[1]")).sendKeys("Cotton");

如果此选项在您的应用程序中不起作用,请尝试使用 Actions 类。

Actions action = new Actions(driver);
WebElement firstDropDown = driver.findElement(By.xpath("(//*[text() = 'T-shirt Fabric']//following::input)[1]"));
action.moveToElement(firstDropDown).click().build().perform(); 
action.sendKeys(Keys.ARROW_RIGHT).sendKeys(Keys.BACK_SPACE).sendKeys(Keys.BACK_SPACE).release().build().perform();
action.sendKeys("Cotton").build().perform();
action.sendKeys(Keys.TAB).build().perform();

你可以把它变成一个方法,然后像这样在每个下拉菜单中重用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-26
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多