java - How to check if button clicked, IF form is actually submitted Selenium / TestNG -


i new java/selenium/testng, have issue run 4 sets of data using dataprovider, however, 1 set of data incorrect purpose of testing test works. first check button displayed clicked. want able check button clicked , check if form submitted if form not submitted print error. unsure on how code below:

webelement  login = driver.findelement(by.id("dijit_form_button_1_label"));         //if statement - check if element displayed before clicking on login button.       if(login.isdisplayed()){           login.click();           //main event 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 | ");     } 

the test displays error message "logout failed" should display first message "login failed" how check if login , form submitted successfully?

the reason prints second message code runs passed point , selenium cant see logout button displayed.

any thoughts on going wrong?

try this:

private static outbutton = by.id("dijit_form_button_0_label"); if(driver.findelements(outbutton).size() > 0) {     logout.click();     reporter.log("logout successful  | "); } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -