Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.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 如何等待属性具有不同的值?_Java_Selenium Webdriver_Webdriver_Webdriverwait_Expected Condition - Fatal编程技术网

Java 如何等待属性具有不同的值?

Java 如何等待属性具有不同的值?,java,selenium-webdriver,webdriver,webdriverwait,expected-condition,Java,Selenium Webdriver,Webdriver,Webdriverwait,Expected Condition,当我们没有在屏幕上等待时 <div id="divWait" style="cursor: wait; position: absolute; left: 0%; top: 0%; background: transparent; padding: 3px; width: 100%; height: 100%; display: none;"> 但它不起作用我们可以等到显示属性不存在 WebDriverWait wait = new WebDriverWait(driver,60)

当我们没有在屏幕上等待时

<div id="divWait" style="cursor: wait; position: absolute; left: 0%; top: 0%; background: transparent; padding: 3px; width: 100%; height: 100%; display: none;">

但它不起作用

我们可以等到
显示
属性不存在

WebDriverWait wait = new WebDriverWait(driver,60);

wait.until(new ExpectedCondition<Boolean>() {   
boolean isAttributeNotPresent= false;
    public Boolean apply(WebDriver driver) 
{
        WebElement button = driver.findElement(By.id("divWait"));

if(button.isDisplayed()
{

try{
        button.getAttribute("display");
} 
catch(Exception e)
 {
isAttributeNotPresent= true;
return isAttributeNotPresent;
}}
}});
WebDriverWait wait=newwebdriverwait(驱动程序,60);
等待.until(新的ExpectedCondition(){
布尔值isAttributeNotPresent=false;
公共布尔应用(WebDriver驱动程序)
{
WebElement按钮=driver.findElement(By.id(“divWait”);
if(button.isDisplayed()
{
试一试{
getAttribute(“显示”);
} 
捕获(例外e)
{
isAttributeNotPresent=真;
返回isAttributeNotPresent;
}}
}});

注意:忽略语法错误,因为我正在从移动键盘键入内容

似乎您已接近。要等待属性显示:无从样式属性中删除,而不是预期的条件,如
invisibilityOfElementLocated()
您必须诱导WebDriverWait以实现元素定位()的可见性,并且您可以使用以下任一选项:

  • css选择器

    WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#divWait")));
    
  • xpath

    WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='divWait']")));
    

等待属性更改或等待获取属性删除,如“显示”获取删除我知道,为其编码?那么问题是什么?什么是“它不工作”意思是?它没有完成预期的任务,或者它抛出了一个错误,或者?用信息更新您的问题,例如完整的错误消息,或者对发生了什么或没有发生什么的很好的描述。如果您发布的XPath是您实际使用的,那可能是错误,因为它的语法不正确。当您有一个ID.你到底想做什么?等待等待出现在屏幕上或消失或???请编辑你的问题并添加更多详细信息。
WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#divWait")));
WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='divWait']")));