C# 使用Selenium C在Materialize CSS上选择下拉项

C# 使用Selenium C在Materialize CSS上选择下拉项,c#,selenium,xpath,selenium-webdriver,css-selectors,C#,Selenium,Xpath,Selenium Webdriver,Css Selectors,我想在下拉字段中选择项目。页面使用MaterializeCSS,我使用的是SeleniumWebDriver C 我最后一次尝试是: IWebElement tipoLoja = driver.FindElement(By.XPath("//select[@id='tipo_empresa']")); SelectElement selectTipoLoja = new SelectElement(tipoLoja); selectTipoLoja.SelectByValue("0"); 但结

我想在下拉字段中选择项目。页面使用MaterializeCSS,我使用的是SeleniumWebDriver C

我最后一次尝试是:

IWebElement tipoLoja = driver.FindElement(By.XPath("//select[@id='tipo_empresa']"));
SelectElement selectTipoLoja = new SelectElement(tipoLoja);
selectTipoLoja.SelectByValue("0");
但结果是:

OpenQA.Selenium.NoSuchElementException:无法找到元素://select[@id='tipo\u empresa']

HTML代码:

<br>
<div class="input-field col  s12 m4 l4 ">
<div class="select-wrapper">    
    <span class="caret">▼</span>
    <input class="select-dropdown" readonly="true" data-activates="select-options-fe6e0db4-d829-b47a-86e7-0a3d5b55e74e" value="Selecione" type="text">
    <ul id="select-options-fe6e0db4-d829-b47a-86e7-0a3d5b55e74e" class="dropdown-content select-dropdown ">
        <li class="disabled "></li>
        <li class=""></li>
        <li class=""></li>
        <li class=""></li>
    </ul>
    <select data-val="true" data-val-required="Informe o Tipo da Loja." id="tipo_empresa" name="TipoLoja">
        <option value="" disabled="disabled" selected="selected">Selecione</option>
        <option value="0">Matriz</option>
        <option value="1">Filial</option>
        <option value="2">Centro de Distribuição</option>
    </select>
    </div>
    <label for="tipo_empresa">Tipo da Loja*</label>
</div>

我有相同的代码,我试图找到元素 通过使用Firefox中的firefug使用xpath,它成功了。 典型例子:

WebElement inputDrop = driver.findElement(By.xpath("/html/body/main/div[2]/div[1]/form/div/div[2]/div[3]/div/div[2]/div/input"));
inputDrop.click();
线程10000

            WebElement type = driver.findElement(By.xpath("/html/body/main/div[2]/div[1]/form/div/div[2]/div[3]/div/div[2]/div/ul/li[3]/span"));
            type.click();

欢迎来到stackoverflow!请把html放在问题本身,因为链接过时了,像我这样的一些人无法访问外部网站。否则,如果您在执行这一行之前等待几秒钟,那么在调试时这是否起作用?driver.FindElementBy.XPath//select[@id='tipo_empresa'];?从HTML来看,SELECT可能是隐藏的,上面的UL作为下拉菜单。尝试单击UL,然后单击包含所需文本的LI。另外,当您所做的只是与ID交互时,为什么要使用XPath?只需使用By.Id.Sorry@mrfreester我已经把代码放在问题中了。我还没试过这个。我会试试。@JeffC,问题是我不知道代码是否与ID一起工作,因为ID行在代码的末尾。但我将尝试使用ID。我尝试使用selecting By.ID,但没有成功。IWebElement tipoLoja=driver.FindElementBy.Idtipo_empresa;SelectElement selectTipoLoja=新SelectElement Tipoloja;selectTipoLoja.selectbytext;结果是>OpenQA.Selenium.ElementNotVisibleException: