python - Checking for a field error using Selenium Webdriver -


i've been trying implement tests check field validation in forms. check specific field error messages straightforward, i've tried generic check identify parent element of field error class. isn't working.

a field error has following html;

<div class="field clearfix error ">     <div class="error">         <p>please enter value</p>     </div>     <label for="id_fromdate">     <input id="id_fromdate" type="text" value="" name="fromdate"> </div> 

so check error i've got following function;

def assertvalidationfail(self, field_id):     # checks div.error sibling element     el = self.find(field_id)     try:         error_el = el.find_element_by_xpath('../div[@class="error"]')     except nosuchelementexception:         error_el = none     self.assertisnotnone(error_el) 

so el input field, xpath fails. believed ../ went level in same way command line navigation - not case?

misunderstood question earlier. may try following logic: find parent div, check if contains class error, rather find parent div.error , check nosuchelementexception.

because .. way go upper level, ../div means parent's children div.

// non-working code, logic parent_div = el.find_element_by_xpath("..") # parent div self.asserttrue("error" in parent_div.get_attribute("class")) 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -