Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.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 Selenium等待ExpectedConditions.attributeToBe的行为不符合预期_Java_Eclipse_Selenium_Expected Condition - Fatal编程技术网

Java Selenium等待ExpectedConditions.attributeToBe的行为不符合预期

Java Selenium等待ExpectedConditions.attributeToBe的行为不符合预期,java,eclipse,selenium,expected-condition,Java,Eclipse,Selenium,Expected Condition,我正在尝试对元素属性执行wait.until,如下所示 public static void WaitForElementSize(WebElement element, WebDriver driver, int timeoutInSeconds) { if (timeoutInSeconds > 0) { System.out.print(element.getAttribute("style"));

我正在尝试对元素属性执行wait.until,如下所示

public static void WaitForElementSize(WebElement element, WebDriver driver, int timeoutInSeconds)
    {
        if (timeoutInSeconds > 0)
        {
            System.out.print(element.getAttribute("style"));

            WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
            wait.until(ExpectedConditions.attributeToBe(element, "style", "top: 0px;"));
        }
    }
我从打印行知道该属性与预期的一样,即“top:0px;”,但当我在等待中单步执行代码时,直到UI中的元素被“单击”并更改为关闭(在本例中,样式更改为“top:120px;”)。然后该方法从一开始就开始,然后失败,因为它现在是错误的

如果您对该方法重新运行和更改值的原因有任何帮助,我们将不胜感激

我也试过

wait.until(e -> element.getAttribute("style") == "top: 0px;");

但由于其他原因,此操作失败,因此尝试了另一种方法。

atributetobe将执行等于字符串的方法,因此,如果样式中有其他内容,则将失败,请尝试使用包含以下属性的属性:

wait.until(ExpectedConditions.attributeContains(element, "style", "top: 0px;"));
这是行不通的:

wait.until(e -> element.getAttribute("style") == "top: 0px;"); 
您需要使用:

element.getAttribute("style").equals("top: 0px;) 

比较字符串

通过.id(“我的元素id”)查找元素没有问题

wait.until(
ExpectedConditions.attributeToBe(By.id("my-element-id"), 
"atrributeNameString", 
"attributeValueString" )
);`
在您的代码中“单击”UI中的Where is元素是否可能重复?