How to check if element is ready to click

时间:2017-06-15 10:05:29

标签: c# selenium testing automation

I want to explicitly wait till my element is enabled to click on screen. But currently what happened is element is visible but due to loading symbol driver is not able to click element & code fails. If I use implicate wait then code works. any suggestions

WebDriverWait wait1 = new WebDriverWait(driver, new TimeSpan(0,0,60));
wait1.Until(ExpectedConditions.ElementSelectionStateToBe(By.XPath(GPDNav),true));
// wait1.Until(ExpectedConditions.ElementIsVisible(By.XPath(GPDNav)));
IWebElement gpdNav = driver.FindElement(By.XPath(GPDNav));
gpdNav.Click();

2 个答案:

答案 0 :(得分:0)

Try using two explicit waits, First one to wait until the "loading" symbol disappears and the second one to wait until the "button" is clickable.

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[loading]")));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[button]")));

答案 1 :(得分:0)

您必须等待加载元素关闭。找到loading元素的xpath并将其放在代码下面并尝试它。我们的应用程序中有相同类型的加载符号,在等待加载元素的隐身后它正常工作。

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.js"></script>

<div id="app">
  <label v-for="(field, index) in fields">
    {{ field.name }}:
    <input ref="fields" :value="field.value" v-bind:class="dataFieldClass(index)">
  </label>
</div>