有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在自动测试中从Kendo UI MVVM下拉列表中选择值?

有人能帮我用SeleniumJava从KendoUIMVVM下拉列表中选择一个值吗

<input class="k-input fieldFullWidth" autocomplete="off" style="width: 100%;" title="" role="combobox" aria-expanded="false" tabindex="0" aria-disabled="false" aria-autocomplete="both" aria-owns="ddStore_listbox" type="text">

<input id="ddStore" class="fieldFullWidth" data-role="combobox" style="display: none;" aria-disabled="false" data-bind="value: selectedAsset.StoreID, comboboxText: selectedAsset.StoreName">

我尝试使用JavascriptExecutor。但是,它给了我组织。openqa。硒。WebDriverException:未知错误:无法设置null错误的属性“值”

jse.executeScript("document.getElementById('ddstore').value = '1';");

谢谢


共 (2) 个答案

  1. # 1 楼答案

    使用ExplicitWait等待<input>标记元素的可见性,然后将下拉值作为输入发送

    WebDriverWait wait = new WebDriverWait(driver, 120);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ddStore")));
    
    driver.findElement(By.id("ddStore")).sendKeys("dropDown_Value"); // send your dropdown value as input
    

    `

    另一种替代方法是使用JavascriptExecuter,因为您的标记包含属性style="display: none;",所以可能会更改元素的不可见性

     JavascriptExecutor jse = (JavascriptExecutor)driver;
     jse.executeScript("arguments[0].value='your_dropdown_value';",driver.findElement(By.id("ddStore")));
    
  2. # 2 楼答案

    您可以尝试以下代码来选择下拉值:

    Select mydrpdwn = new Select(driver.findElement(By.id("ddStore"))); //id of dropdown  
    mydrpdwn.selectByVisibleText("name");// Value you wanted to select