点击事件后,我需要等待元素属性发生变化,然后再继续(点击事件导致某些元素移出焦点,而某些其他元素通过 JS 获得焦点)
在花时间在网络驱动程序中搜索“waitForAttribute”(selenium 1 命令)的可靠替代方案之后......我可以让下面的代码工作。但我不确定这是否是最好的实现...
还有其他更好的解决方案吗?
wait = new WebDriverWait(wedriver1, TimeSpan.FromSeconds(5));
.....
button.Click();
wait.Until(webdriver1 => webdriver2.webelement.GetAttribute("style").Contains("display: block"));
另外,任何人都可以分享一个链接,告诉我如何使用 webdriver 处理 AJAX 事件更改。
最佳答案
我建议使用 org.openqa.selenium.support.ui.ExpectedConditions.attributeToBe(WebElement element, String attribute, String value)
。
例如
WebDriverWait wait = new WebDriverWait(driver, 5); // time out after 5 seconds
someElement.click();
wait.until(ExpectedConditions.attributeToBe(someElement, "sort-attribute", "ascending"));
( docs )
关于c# - 等待 Selenium Webdriver 更改的最佳实践?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10426321/