试图在selenium和C#中找到具有span id的元素,但是找不到错误元素

时间:2018-03-02 18:06:13

标签: c# selenium selenium-webdriver

我想单击位于菜单栏中的元素并单击它,但我收到错误

OpenQA.Selenium.ElementNotVisibleException: element not visible

HTML:

<div id="et_top_search">
    <span id="et_search_icon"/>
</div>

C#代码:

_driver.FindElementByXPath(".//span[@id='et_search_icon']").Click();

1 个答案:

答案 0 :(得分:0)

您必须诱导 WebDriverWait 才能点击该元素,如下所示:

wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(".//span[@id='et_search_icon']"))).Click();