如何用Selenium C#从Devextreme下拉菜单中选择一个值?

问题描述 投票:0回答:1

我需要用NUnit或纯粹的Selenium从下拉菜单中选择值(House_TypeList中的任何值)。.它们在HTML中看不到。我试过通过xpath,通过名称,通过span包含等等等等来选择,我试过发送下键。我一直在等待元素变得可见。我已经没有办法了。没有任何效果。我还没有尝试过移动光标,并试图通过这个方法来选择它,但在实施过程中遇到了一些问题,而且考虑到我的运气,我也不太相信它会成功。

我是一个初学者,也许我做了一些错误的地方。但我成功地管理了其他的输入、按钮、导航......。

我已经检查了其他类似的问题,但无法找到答案,将为我工作。

这在这里有可能吗?

源头:我需要选择数值(任何数值)。

<div class="dx-item dx-box-item" style="display: flex; min-height: auto; flex-grow: 1; flex-shrink: 1;"
  <div class="dx-item-content dx-box-item-content" style="width: auto; height: auto; display: flex; flex-direction: column; flex-basis: 0px; flex-grow: 1;">
    <div class="dx-first-col dx-last-col dx-field-item dx-field-item-required dx-col-0 dx-flex-layout dx-label-h-align">
      <label class="dx-field-item-label dx-field-item-label-location-left" for="dx_dx-...._typeId">
        <span class="dx-field-item-label-content" style="width: 159px;">
          <span class="dx-field-item-label-text">Type:</span>
          <span class="dx-field-item-required-mark">&nbsp;*</span>
        </span>
      </label>
      <div class="dx-field-item-content dx-field-item-content-location-right">
        <div class="dx-textbox dx-texteditor dx-texteditor-empty dx-dropdowneditor-button-visible dx-widget dx-dropdowneditor-field-clickable dx-dropdowneditor dx-selectbox dx-validator dx-visibility-change-handler" id="slb_HouseManagement_EditHouse_TypeList">
          <div class="dx-dropdowneditor-input-wrapper dx-selectbox-container">
            <input type="hidden" value="" name="typeId">
            <div class="dx-texteditor-container">
              <input autocomplete="off" id="dx_dx-4e..._typeId" class="dx-texteditor-input" aria-haspopup="true" aria-autocomplete="list" type="text" readonly="" spellcheck="false" tabindex="0" aria-expanded="false" role="combobox" aria-required="true">
              <div data-dx_placeholder="Select..." class="dx-placeholder"></div>
              <div class="dx-texteditor-buttons-container">
                <div class="dx-dropdowneditor-button dx-button-normal dx-widget" type="button">
                  <div class="dx-button-content">
                    <div class="dx-dropdowneditor-icon"></div>
                  </div></div></div></div></div></div></div></div></div></div>
c# selenium automated-tests dropdown devextreme
1个回答
0
投票

你提供的DOM不包含任何列表元素。所以我不能在这里分享确切的工作代码。我将分享一些示例,你可以更新和使用。

使用Selenium从列表中选择项目,你有两个选项可以选择:---------。

  1. 选择类

制作一个select类的对象,如下图所示

 Select obj =new Select(driver.findElement(By.id("search-box")));

然后你可以在这个select obj上使用几个函数。

obj.selectByVisibleText("Apartment");
Or
obj.selectByIndex(2);
or
obj.selectByValue("Farmhouse");

你也可以得到一个List中的所有元素,然后围绕着这个List进行工作。

List <WebElement> myHouseList = obj.getOptions();

System.out.println(myHouseList.size());

2.诉讼类

 driver.manage().timeouts().implicitlyWait(10 , TimeUnit.SECONDS);
  ele= driver.findElement(By.linkText("HouseList"));
  Actions act = new Actions(driver);
  act.moveToElement(ele).click();

  WebElement webele = driver.findElement(By.linkText("Apartment"));
  act.moveToElement(webele).click().build().perform();

希望对你有所帮助!


0
投票

完成了。发现它在 极速支持该用户的问题有点不同,但它也解决了我的问题。

IWebElement selectedItem = driver.FindElement(By.XPath("//div[@role='option']/div[text()='Apartment']"));
selectedItem.Click();
© www.soinside.com 2019 - 2024. All rights reserved.