xpath - Selenium Webdriver: stale element reference -


am getting below error:

stale element reference: element not attached page document. when select country country dropdown page gets refreshed since have used 'onchange' attribute, when try locate rest of fields in form throwing me stated exception.

note: have cross verified locators before , after page gets loaded, there no change in of locators used id's.

here html,

<form method="post" action="/eclaims/app" name="mainform" id="mainform"     accept-charset="utf-8">     <div style="display: none;">         <input type="hidden" name="formids"             value="iferrors,haserrors,if,if_0,statusdate1,if_1,if_3,if_5,if_7,if_2,calldate,if_8,if_4,countrylist,if_9,if_6,languagelist,if_10,if_11,if_12,customeremail,if_13,if_14,customertitle,if_15,customerfirstname,if_16,if_17,customerlastname,if_18,customercompany,if_19,if_20,if_21,customerfaxphonecode,customerfaxnumber,if_22,if_23,customerphonecode,customerphonenumber,if_24,if_25,qualificationsystem,if_26,if_27,caseid,if_28,if_29,productnumber,if_30,if_31,serialnumber,if_32,if_33,if_34,purchasedate,if_35,if_36,problemdescription,if_37,qualificationagent,if_38,if_39,if_40,canceldoaauth,if_41,submit_0,if_42,submit_1,if_43,submit_2,if_44,if_45,if_46,if_47,submit_6,submit_7,submit_8">         <input type="hidden" name="component" value="mainform"> <input             type="hidden" name="page" value="doaauthorisationform">     </div>     <table width="100%">         <tbody>             <tr>                 <td colspan="3"></td>             </tr>             <tr class="theme">                 <th width="100%" colspan="3">                     <h2 class="themeheader">authorisation return doa product</h2>                 </th>             </tr>             <tr>             </tr>             <tr>                 <td colspan="10"><font color="red">please obtain valid                         proof of purchase customer before proceeding                         form.&nbsp;</font></td>             </tr>             <tr>                 <td colspan="3"><hr width="100%"></td>             </tr>              <!-- <tr style="visibility: hidden;">                         <td>                             <span key="label.status" ></span>                         </td>                         <td class="inputformcell">                             <span jwcid="statuslist" ></span>                         </td>                     </tr> -->             <tr style="visibility: hidden;">                 <td>status date</td>                 <td class="inputformcell"><input type="text" name="statusdate1"                     value="" title="dd mmm yyyy" id="statusdate1">&nbsp;<a                     href="javascript:calendar_statusdate1.toggle(document.mainform.statusdate1);"><img                         src="/eclaims/app?digest=d1154f8b7bf653ba6128f8cb1f5c8e95&amp;path=%2forg%2fapache%2ftapestry%2fform%2fdatepickericon.png&amp;service=asset"                         border="0"></a></td>             </tr>             <tr>                 <td>call date<font color="red"> *</font>                 </td>                 <td class="inputformcell"><input type="text" name="calldate"                     value="" title="dd mmm yyyy" id="calldate">&nbsp;<a                     href="javascript:calendar_calldate.toggle(document.mainform.calldate);"><img                         src="/eclaims/app?digest=d1154f8b7bf653ba6128f8cb1f5c8e95&amp;path=%2forg%2fapache%2ftapestry%2fform%2fdatepickericon.png&amp;service=asset"                         border="0"></a></td>             </tr>             <tr>                 <td>country<font color="red"> *</font>                 </td>                 <td class="inputformcell"><select name="countrylist"                     id="countrylist" style="width: 180px;"                     onchange="javascript:onchangecountry(this);">                         <option value="">--please select--</option>                         <option value="af">afghanistan</option>                         <option value="as">american samoa</option>                         <option value="au" selected="selected">australia</option>                         <option value="bd">bangladesh</option>                         <option value="wf">wallis , futuna</option>                         <option value="ws">samoa</option>                 </select></td>             </tr>             <tr>                     <td>language<font color="red"> *</font>                 </td>                 <td class="inputformcell"><select name="languagelist"                     id="languagelist" style="width: 180px;">                         <option value="" selected="selected">--please select--</option>                         <option value="en">english</option>                 </select></td>              </tr>             <tr>                 <td>customer email<font color="red"> *</font><font color="red">                         *</font>                 </td>                 <td class="inputformcell"><input type="text"                     name="customeremail" value="" id="customeremail"></td>             </tr>              <tr>                 <td colspan="3">**fax number mandatory 'save &amp; fax',                     e-mail mandatory 'save &amp; mail'</td>              </tr>             <tr>                 <td class="section_content"><input type="submit"                     name="submit_6" value="[button.submit1]" id="submitdummy"                     class="primbutton" style="visibility: hidden;"></td>                 <td class="section_content"><input type="submit"                     name="submit_7" value="[button.submit2]" id="submitauth"                     class="primbutton" style="visibility: hidden;"></td>             </tr>             <tr>                 <td class="section_content"><input type="submit"                     name="submit_8" value="[button.submit2]" id="submitmailauth"                     class="primbutton" style="visibility: hidden;"></td>             </tr>         </tbody>     </table> </form> 

i have tried following solutions,

new webdriverwait(driver, 500)         .ignoring(staleelementreferenceexception.class)         .until(new predicate<webdriver>() {             public boolean apply(@nullable webdriver driver) {                 select selectlanguage;                 try {                     selectlanguage = new select(getwebelement("apj.newdoa.language"));                     selectlanguage.selectbyvalue("en");                 } catch (exception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }                  return true;             }         }); 

2nd solution,

wait<webdriver> wait = new fluentwait<webdriver>(driver)                 .withtimeout( 120, timeunit.seconds )                 .pollingevery( 20, timeunit.seconds )                 .ignoring( nosuchelementexception.class, staleelementreferenceexception.class );         // using customized expected condition         select foo1 = wait.until(new function<webdriver, select>() {             select selectlanguage;             public select apply(webdriver driver) {                 try {                     selectlanguage = new select(getwebelement("apj.newdoa.language"));                     logger.info("value of option:\t" +selectlanguage.tostring());                     return selectlanguage = new select(getwebelement("apj.newdoa.language"));                 } catch (exception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }                 return selectlanguage;             }         });          foo1.selectbyvalue("en"); 

thanks in advance


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -