【问题标题】:How I set a value in input-select (React.js field) with selenium c#?如何使用 selenium c# 在输入选择(React.js 字段)中设置值?
【发布时间】:2018-08-30 22:01:45
【问题描述】:

人。

我没有使用 selenium c# 获取输入选择值(React.js 字段)。该字段获取服务的值。

Obs:我尝试使用 SendKeys 命令填充字段,但我不正确。

是 HTML 代码:

<div class="Select selectbox-select Select--single is-clearable is-searchable"><div class="Select-control"><span class="Select-multi-value-wrapper" id="react-select-2--value"><div class="Select-placeholder">Selecione...</div><div class="Select-input" style="display: inline-block;"><style>input#undefined::-ms-clear {display: none;}</style><input role="combobox" aria-expanded="false" aria-owns="" aria-haspopup="false" aria-activedescendant="react-select-2--value" value="" style="width: 5px; box-sizing: content-box;"><div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 16px; font-family: roboto-regular, sans-serif; font-weight: 400; font-style: normal; letter-spacing: normal; text-transform: none;"></div></div></span><span class="Select-arrow-zone"><span class="Select-arrow"></span></span></div></div>

<div class="Select selectbox-select Select--single is-clearable is-searchable has-value"><div class="Select-control"><span class="Select-multi-value-wrapper" id="react-select-2--value"><div class="Select-value"><span class="Select-value-label" role="option" aria-selected="true" id="react-select-2--value-item">000001 - EST GO</span></div><div class="Select-input" style="display: inline-block;"><style>input#undefined::-ms-clear {display: none;}</style><input role="combobox" aria-expanded="false" aria-owns="" aria-haspopup="false" aria-activedescendant="react-select-2--value" value="" style="width: 5px; box-sizing: content-box;"><div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 16px; font-family: roboto-regular, sans-serif; font-weight: 400; font-style: normal; letter-spacing: normal; text-transform: none;"></div></div></span><span class="Select-clear-zone" title="Clear value" aria-label="Clear value"><span class="Select-clear">×</span></span><span class="Select-arrow-zone"><span class="Select-arrow"></span></span></div></div>

这是我的代码:

//ParametersPage.cs
 public void preencherCampoProduto(string produto)
        {
            inputSelectProduto.Clicks();
            IWebElement dropdownValue = retornaXpathCamposInputSelect(produto);
            dropdownValue.Clicks();
        }

public IWebElement retornaXpathCamposInputSelect(string valor)
        {
            return driver.FindElement(By.XPath("//div[contains(text(),'" + valor + "')]"));
        }

//ParametersTest.cs
        [TestMethod]
        public void OLE_testParametrosPreencherConvenio()
        {
            autenticacao.RealizarAutenticacao(usuarioCorreto, senhaCorreta);
            paginaInicial.acessarMenuRemuneracaoCadastroListagem();
            parametro.preencherCampoConvenio("005045 - CARBEL");
            //Assert.IsTrue(alerta.MensagemValidacao().Contains(MSG_RelatorioDataInicioFimForaLimite));
        }

谢谢大家!!!

【问题讨论】:

    标签: selenium selenium-webdriver selenium-chromedriver selenium-rc selenium-grid


    【解决方案1】:

    尝试使用动作类:

    IWebElement myElement = Driver.Instance.FindElement(By.XPath("//*[@id='field_" + SetEnvironmentJourney.EnvironmentControlId + "_" + elementId + "']")); 动作act = new Actions(Driver.Instance); act.MoveToElement(myElement).Click().Build().Perform();

                IWebElement myItem = myElement.FindElement(By.XPath("//div[contains(text(),'" + p + "')]"));
                act.Click(myItem).Build().Perform();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-26
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多