Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何等待css属性更改?_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java 如何等待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

如何告诉SeleniumWebDriver等待特定元素在css中设置特定属性

我想等待:

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;");