如何解决具有淡入淡出效果的按钮有问题
Sleep()`可以正常工作,但是如果没有它们,它就无法工作,我尝试了不同的方法,例如可见性,elementtobeclickeable等,但问题是该元素还没有准备好被选中,因为正在淡化关闭。
_wait.Until(SeleniumExtras.WaitHelpers.
ExpectedConditions.PresenceOfAllElementsLocatedBy(By.XPath("//*[@id=\"DataTables_Table_7_wrapper\"]/div[2]/div[1]/div/table/thead/tr/th[1]/input")));
//Thread.Sleep(1000);
WEValuador.ChkBoxAllRefacciones.Click();
WEValuador.BtnModificar.Click();
_wait.Until(SeleniumExtras.WaitHelpers.
ExpectedConditions.PresenceOfAllElementsLocatedBy(By.XPath("/html/body/div[5]/a[4]/span")));
//Thread.Sleep(1000);
WEValuador.BtnAutorizacion.Click();
_wait.Until(SeleniumExtras.WaitHelpers.
ExpectedConditions.PresenceOfAllElementsLocatedBy(By.XPath("/html/body/div[5]/a[1]/span")));
//Thread.Sleep(1000);
WEValuador.BtnAutorizado.Click();
ASU.AssertMsjs();
这是错误:
Message:
System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.InvalidOperationException : unknown error: Element <input class="selected-item-all select-checkbox" data="" type="checkbox" name="" value=""> is not clickable at point (330,490). Other element would receive the click: <div class="modal show" id="SpinnerLoader" tabindex="-1" role="dialog" aria-labelledby="loadMeLabel" data-backdrop="static" data-keyboard="false" style="padding-right: 17px; display: block;">...</div>
(Session info: chrome=85.0.4183.83)
(Driver info: chromedriver=2.37.543627 (63642262d9fb93fb4ab52398be4286d844092a5e),platform=Windows NT 10.0.18362 x86_64)
解决方法
要对Click()
而不是PresenceOfAllElementsLocatedBy()
上的任何单个元素,必须为ElementToBeClickable()
引入 WebDriverWait ,并且可以使用以下Locator Strategy :
_wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id=\"DataTables_Table_7_wrapper\"]/div[2]/div[1]/div/table/thead/tr/th[1]/input")));
,
在这种情况下,JavaScript执行器确实可以帮助解决问题。而不是等待ElementToBeClickable
和Visible
。使用Java脚本
Java-
WebElement element = driver.findElement(By.id("gbqfd"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();",element);
C#-
IJavascriptExecutor jse = (IJavascriptExecutor) driver;
jse.executeScript("arguments[0].click()= element );
,
This was my solution,you could to quit thread.sleep();
公共静态IWebElement SafeWaitForDisplayed(IWebElement webElement) {
var w = new DefaultWait<IWebElement>(webElement);
w.Timeout = TimeSpan.FromSeconds(30);
w.IgnoreExceptionTypes(typeof(NoSuchElementException),typeof(StaleElementReferenceException),typeof(System.Reflection.TargetInvocationException));
return w.Until(ctx =>
{
var elem = webElement;
if (elem.Displayed) {
Thread.Sleep(500);
return elem;
}
else
return null;
});
//Thread.Sleep(100);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。