Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.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/TestNG_Java_Selenium_Selenium Webdriver_Testng - Fatal编程技术网

Java 如何检查按钮是否点击,表单是否实际提交Selenium/TestNG

Java 如何检查按钮是否点击,表单是否实际提交Selenium/TestNG,java,selenium,selenium-webdriver,testng,Java,Selenium,Selenium Webdriver,Testng,我是java/selenium/testNG新手,我遇到了一个问题,我使用dataprovider运行了4组数据,但是,仅为了测试测试是否有效,一组数据是不正确的。我首先检查按钮是否显示,然后单击。我希望能够检查按钮是否被单击,然后检查表单是否已提交。如果表单未提交,则检查打印错误。我不确定如何执行此操作我的代码如下: WebElement login = driver.findElement(By.id("dijit_form_Button_1_label")); //If

我是java/selenium/testNG新手,我遇到了一个问题,我使用dataprovider运行了4组数据,但是,仅为了测试测试是否有效,一组数据是不正确的。我首先检查按钮是否显示,然后单击。我希望能够检查按钮是否被单击,然后检查表单是否已提交。如果表单未提交,则检查打印错误。我不确定如何执行此操作我的代码如下:

WebElement  login = driver.findElement(By.id("dijit_form_Button_1_label"));


      //If statement - will check if element is Displayed before clicking on login button.
      if(login.isDisplayed()){
          login.click();
          //Main Event is logged If Passed
          Reporter.log("Login Form Submitted  | ");
          logger1.info("Submit Button Clicked");
      }else{  

          Reporter.log("Login Failed  | ");
          Assert.fail("Login Failed - Check Data | ");
          //Main Event Log Fail  
         }  




    WebElement logout = driver.findElement(By.id("dijit_form_Button_0_label"));

    if(logout.isDisplayed()){
        logout.click();
    Reporter.log("Logout Successful  | ");
    }else {
        Reporter.log("Logout Failed");
        Assert.fail("Logout Failed - Check Data | ");
    }
测试显示一条错误消息“注销失败”,但它应该显示第一条消息“登录失败”。如何让它检查登录和表单是否已成功提交

它打印第二条消息的原因是代码运行通过了该点,并且selenium无法看到显示的注销按钮

你认为我做错了吗?

试试这个:

private static By outButton = By.id("dijit_form_Button_0_label");
if(driver.findElements(outButton).size() > 0)
{
    logout.click();
    Reporter.log("Logout Successful  | ");
}

提交表单后,您应该让webdriver等待某个条件为真

诸如此类

int timeout = 30
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(new Function <WebDriver, Boolean>(){
    //@Override
    public Boolean apply(WebDriver driver) {                    
            //if the login has been successful return true
            //if not, return false
        }               
    });   
int timeout=30
WebDriverWait wait=新的WebDriverWait(驱动程序,超时);
wait.until(新函数(){
//@凌驾
公共布尔应用(WebDriver驱动程序){
//如果登录成功,则返回true
//如果不是,则返回false
}               
});   

很抱歉,我不确定这是否正确。我想检查是否显示了web元素。如果是,则单击元素并提交表单,但是,我希望此时还检查表单是否已提交,以及表单是否失败。Reporter.log(“Login failed |”);Assert.fail(“登录失败-检查数据|”);如果由于数据不正确导致登录失败,则不会显示