Chrisko Chrisko - 7 months ago 59
Javascript Question

Tricky Selector casperjs hidden div

i have a, in my opinion really tricky form. The form changes div's, hidden fields & id's on every reload. and i cant find a pattern how it changes.

here's an example for the class .box.box500:

<div class="box box500" style="float:left;display:none;">
<span class="errorText"></span>
<br>
<input id="czoyNToiaWhfYlNEaDg0ZGNkVi00bUxtckxLZ2cuLiI7" type="text" name="czoyNToiaWhfYlNEaDg0ZGNkVi00bUxtckxLZ2cuLiI7" value="">
</div>
<div id="boxFirma" style="display: none;margin-top: 20px;">
<div class="" style="float:left;left;margin-left:10px;display:none;">
<a name="personal"></a>
<div style="overflow:hidden; margin-top: 20px;">
<div class="box box500 " style="display:none;">
<input id="czoyNToiaWhfYlNEaDg0ZGNkUjh3d2tOOFJFd2cuLiI7" type="text" value="" name="czoyNToiaWhfYlNEaDg0ZGNkUjh3d2tOOFJFd2cuLiI7">
<br>
<span class="errorText"></span>
</div>
<div class="box box500 " style="float: left;">
<input id="czoyNToiaWhfYlNEaDg0ZGNlVFpMRjFVWjZicEEuLiI7" type="hidden" value="" name="czoyNToiaWhfYlNEaDg0ZGNlVFpMRjFVWjZicEEuLiI7">
<input id="czoyNToiaVhxemVtUGRZOHluMkNxdE9pWEd1Y1EuLiI7" type="text" value="" name="czoyNToiaVhxemVtUGRZOHluMkNxdE9pWEd1Y1EuLiI7">
<br>
<span class="errorText"></span>
</div>
<div class="box box502 " style="float: left;margin-left: 20px;">
<input id="czoxMzoiaXgtQTNQT3VWVmprLiI7" type="text" value="" name="czoxMzoiaXgtQTNQT3VWVmprLiI7">
<br>
<span class="errorText"></span>
</div>
</div>


sometimes the first hidden div is there, and sometimes not. the id changes on every reload. The hidden input is sometimes the first child, sometimes the second.also the div, sometimes on the frist positionen sometimes on the second. i've really no idea how to identify the input fields.

is it maybe possible to select a input filed like:

this.sendKeys('.box.box500:nth-child(2):style="float: left;" > input:nth-child(2):type="text"', 'text');

Answer

Could you not use the selector:

this.sendKeys('div.box.box500 input[type="text"]:not([style*="display: none"])', ...);

I believe this would find all of the specific inputs type="text" regardless of the order on the page.

Comments