Java 如何等待css属性更改?
如何告诉SeleniumWebDriver等待特定元素在css中设置特定属性 我想等待:Java 如何等待css属性更改?,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,如何告诉SeleniumWebDriver等待特定元素在css中设置特定属性 我想等待: element.getCssValue("display").equalsIgnoreCase("block") 通常,人们会像这样等待元素出现: webdriver.wait().until(ExpectedConditions.presenceOfElementLocated(By.id("some_input"))); 我怎样才能等待显示属性的特定css值呢?我想这对你来说是可行的 webdriv
element.getCssValue("display").equalsIgnoreCase("block")
通常,人们会像这样等待元素出现:
webdriver.wait().until(ExpectedConditions.presenceOfElementLocated(By.id("some_input")));
我怎样才能等待显示属性的特定css值呢?我想这对你来说是可行的
webdriver.wait().until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='some_input'][contains(@style, 'display: block')]")));
对上述答案稍加修改对我有帮助。我必须使用两个
(
s,然后才能通过.XPATH启动,而不是1:
WebDriverWait(浏览器,1000).until(EC.presence\u of_元素的位置((By.XPATH,xpathstring)))
在C#中使用扩展方法:
public static WebDriverWait wait = new WebDriverWait(SeleniumInfo.Driver, TimeSpan.FromSeconds(20));
public static void WaitUntilAttributeValueEquals(this IWebElement webElement, String attributeName, String attributeValue)
{
wait.Until<IWebElement>((d) =>
{
if (webElement.GetAttribute(attributeName) == attributeValue)
{
return webElement;
}
return null;
});
}
这个答案是针对Python的,正如FYII尝试过的那样,但它不起作用//span[contains(text(),'Create Professor')][contains(@style,'color:ł22222')]
。它给元素找不到异常。如果HTML是,请单击此处创建Professor…
。创建Professor从禁用变为禁用(灰色文本)对于黑色粗体文本,我很确定这不会起作用,因为JS对样式的更改不会更改@style的值。OP只需要在元素上使用一个普通的旧等待循环。getCssValue(“display”)
。
IWebElement x = SeleniumInfo.Driver.FindElement(By.Xpath("//..."));
x.WaitUntilAttributeValueEquals("disabled", null); //Verifies that the attribute "disabled" does not exist
x.WaitUntilAttributeValueEquals("style", "display: none;");