Trying to select an option in a check box when a similar string was selected in a previous multi select list

101 views
Skip to first unread message

Helen

unread,
Jul 2, 2012, 11:57:05 AM7/2/12
to co...@googlegroups.com
I am writing tests to fill out quite large forms, with similar values that can be selected.

If I use the option to check options that are a partial match to a previous field's selection, the script will fail saying it can't find the option to select.  I can overcome the issue by making the code use the XPath to select the options, but this seems to be counteracting the point of Coypu?

So if in a previous multi-select list I have selected an option like "abc def", which will then populate the next multi-select list with the option "abc", setting the check option to be "browser.Check("abc");" will throw the error that the object could not be found, but setting it to be "browser.FindXPath(".//XPathLocation/abc").Click();" will select the option.  I am wondering if this error is due to Coypu just matching the first element in the page and not limiting it to the first check box found (as not available unless the multi-select list is open)?

When I get the same problem in the same page but in a different section, I do use the FindSection method to locate the options.  So could it be possible to have another way of selecting an element by providing text and field ID?  Or have I missed something else I should do?

Adrian Longley

unread,
Jul 2, 2012, 4:40:23 PM7/2/12
to co...@googlegroups.com

On 2 Jul 2012, at 16:57, Helen <hnich...@hotmail.com> wrote:

> I am writing tests to fill out quite large forms, with similar values that can be selected.
>
> If I use the option to check options that are a partial match to a previous field's selection, the script will fail saying it can't find the option to select. I can overcome the issue by making the code use the XPath to select the options, but this seems to be counteracting the point of Coypu?
>
> So if in a previous multi-select list I have selected an option like "abc def", which will then populate the next multi-select list with the option "abc", setting the check option to be "browser.Check("abc");" will throw the error that the object could not be found, but setting it to be "browser.FindXPath(".//XPathLocation/abc").Click();" will select the option. I am wondering if this error is due to Coypu just matching the first element in the page and not limiting it to the first check box found (as not available unless the multi-select list is open)?

Possibly. I don't quite follow though. Any chance you could post the exact HTML in the state where it fails, and the test code? Then iI'll get to the bottom of it for you.

Adrian

Helen

unread,
Jul 3, 2012, 4:48:38 AM7/3/12
to co...@googlegroups.com

On Monday, 2 July 2012 21:40:23 UTC+1, Adiel wrote:


Possibly. I don't quite follow though. Any chance you could post the exact HTML in the state where it fails, and the test code? Then iI'll get to the bottom of it for you.

Adrian

I know that the way the multi selects were written are not the expected, but the HTML (that is generated after the selections are made as before the 2nd and 3rd drop-downs would be empty until the previous drop-down selections are made) is as follows:
 <tr style="height: 25px">
                    <td class="formlabel">
                        <span id="ContentPlaceHolder1_ContentPlaceHolder1_lbl4" title="Single or Multi-Category events can be selected by checking the relevant box.">Category</span>
                    </td>
                    <td style="text-align: left" id='cols'>
                        <select size="4" name="ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder1$ddlCategory" multiple="multiple" id="ContentPlaceHolder1_ContentPlaceHolder1_ddlCategory" style="width:178px;">
	<option selected="selected" value="64">Candy</option>
	<option selected="selected" value="65">Chocolate</option>
	<option value="66">Coffee</option>
	<option value="67">Snacks</option>

</select>
                        
                    </td>
                </tr>
                <tr style="height: 25px">
                    <td class="formlabel">
                       <span id="ContentPlaceHolder1_ContentPlaceHolder1_Label2">PPH</span>
                    </td>
                    <td style="text-align: left" id='pgcols'>
                        <select size="4" name="ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder1$ddlProductGroup" multiple="multiple" id="ContentPlaceHolder1_ContentPlaceHolder1_ddlProductGroup" class="normal" style="width:178px;">
	<option selected="selected" value="1347">Africana asortate </option>
	<option selected="selected" value="484">Africana Creme Base</option>
	<option value="485">Africana Plain Base</option>
	<option value="612">Chokotoff 250g stand 10 kg 2010</option>
	<option selected="selected" value="490">Halls Base</option>
	<option value="491">Halls Breezers</option>
	<option selected="selected" value="479">Lila Collection</option>
	<option value="583">Milka  winter 100g</option>
	<option value="882">MILKA AMAVEL 160G</option>
	<option value="615">Milka Bomboane de pom 400g</option>
	<option value="1643">Milka Bunny 60g Ciocolata cu lapte din Alpi</option>
	<option value="511">Milka Cr&#232;me base</option>
	<option value="512">Milka Cr&#232;me Sourcherry</option>
	<option value="513">Milka Desert</option>
	<option value="1644">Milka Kleine Eier Milch creme 75g</option>
	<option value="1349">Milka LED Spring</option>
	<option value="607">Milka limited edition 240g</option>
	<option value="514">Milka Luflee</option>
	<option value="515">Milka Milkinis large</option>
	<option value="516">Milka Milkinis small</option>
	<option value="616">Milka Mos Craciun 20x60g</option>
	<option value="517">Milka plain base</option>
	<option value="518">Milka plain Diet</option>
	<option value="519">Milka plain WholeNuts</option>
	<option value="520">Milka pralines 120g</option>
	<option value="1352">Milka pralines 137.5g</option>
	<option value="521">Milka pralines 150g</option>
	<option value="522">Milka pralines 42g</option>
	<option value="593">Milka Seasonals - all the rest</option>
	<option value="545">Milka snax big</option>
	<option value="546">Milka snax small</option>
	<option value="584">Milka summer</option>
	<option value="523">Milka Tablets Base 200g/250g</option>
	<option value="554">Milka Tablets Base 200g/250g/300g</option>
	<option value="524">Milka Tablets Base 300g</option>
	<option value="525">Milka Wholenuts250g</option>
	<option value="617">Milka winter</option>
	<option value="618">M-JOY Alune 60g</option>
	<option value="619">M-JOY Lapte 60g</option>
	<option value="594">Poiana 200g Base</option>
	<option value="533">Poiana Aerata</option>
	<option value="534">Poiana Baton 30g</option>
	<option value="842">Poiana Chokotoff 238g</option>
	<option value="480">Poiana Chokotoff 266g</option>
	<option value="481">Poiana Chokotoff 38g</option>
	<option value="482">Poiana Chokotoff 95g</option>
	<option value="535">Poiana Chokotoff Intense</option>
	<option value="536">Poiana Cr&#232;me Base</option>
	<option value="538">Poiana Delicii Base</option>
	<option value="1351">Poiana LED Spring</option>
	<option value="540">Poiana Monopraline</option>
	<option value="558">Poiana Monopraline Sour Cherry</option>
	<option value="541">Poiana Plain Base</option>
	<option value="483">Poiana Praline Asortate</option>
	<option value="595">Poping candy</option>
	<option value="596">Smash 50g</option>
	<option value="1355">Stand I love Milka </option>
	<option value="547">Tassimo</option>
	<option value="621">Toblerone alune si stafide 400g</option>
	<option value="611">TOBLERONE OBO 200g Easter&#39;11</option>
	<option value="622">Toblerone Snowtop 100g</option>
	<option value="542">Toblerone Tablets Base</option>
	<option value="599">X-mas Candy</option>

</select>
                        
                    </td>
                </tr>
                <tr style="height: 25px">
                    <td class="formlabel">
                        <span id="ContentPlaceHolder1_ContentPlaceHolder1_lbl5" title="Single or Multi-Brand events can be selected by checking the relevant box.">Brand</span>
                    </td>
                    <td style="text-align: left" id='bcols'>
                        <select size="4" name="ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder1$ddlBrandList" multiple="multiple" id="ContentPlaceHolder1_ContentPlaceHolder1_ddlBrandList" style="width:178px;">
	<option selected="selected" value="345">Africana</option>
	<option value="349">Halls</option>
	<option selected="selected" value="351">Milka</option>

</select>

The scripts I have coded are as follows (I need to open the list before selecting the check boxes, and click outside the list to close them due to how they are written):

if (!string.IsNullOrEmpty(category))
{
//Create the array
List<string> categoryarray = ArrayMaker.CreateArray(category, category1, category2, category3);
//Open the list selection
_eventPage.FindCss("a#ContentPlaceHolder1_ContentPlaceHolder1_ddlCategory.multiSelect").Click();

foreach (var value in categoryarray)
{
//Click the object(s)
_eventPage.Check(value);
}

//To close the list selection, click elsewhere in the screen
_eventPage.FindCss("input#ContentPlaceHolder1_ContentPlaceHolder1_txtName.textbox").Click();
}

//Select the product groups if they are not empty
if (!string.IsNullOrEmpty(pph))
{
//Create the array
List<string> ppharray = ArrayMaker.CreateArray(pph, pph1, pph2, pph3);
//Open the list selection
_eventPage.FindCss("a#ContentPlaceHolder1_ContentPlaceHolder1_ddlProductGroup.multiSelect").Click();

foreach (var value in ppharray)
{
//Click the object(s) - the Check method passes here as the text is unique
_eventPage.Check(value);
}
//To close the list selection, click elsewhere in the screen
_eventPage.FindCss("input#ContentPlaceHolder1_ContentPlaceHolder1_txtName.textbox").Click();
}

//Select the product brands if they are not empty
if (!string.IsNullOrEmpty(brand))
{
//Create the array
List<string> brandarray = ArrayMaker.CreateArray(brand, brand1, brand2, brand3);
//Open the list selection
_eventPage.FindCss("a#ContentPlaceHolder1_ContentPlaceHolder1_ddlBrandList.multiSelect").Click();

foreach (var value in brandarray)
{
//Click the object(s)
//_eventPage.Check(value); - this fails but the next line passes
_eventPage.FindXPath(".//*[contains(@id,'ContentPlaceHolder1_ContentPlaceHolder1_ddlBrandList')]//following-sibling::*//label[contains(text(), '" + value + "')]").Click();
}
//To close the list selection, click elsewhere in the screen
_eventPage.FindCss("input#ContentPlaceHolder1_ContentPlaceHolder1_txtName.textbox").Click();
}

Helen

unread,
Jul 3, 2012, 4:51:52 AM7/3/12
to co...@googlegroups.com
I forgot to say, the scripts are loading in the test scenarios, but the value for brand that fails is "Africana".  The error that is shown is:
Test method EventSmokeTestScenario threw exception:
Coypu.MissingHtmlException: Failed to find field with label, id, name or placeholder: Africana

Adrian Longley

unread,
Jul 3, 2012, 11:08:00 AM7/3/12
to co...@googlegroups.com
On 3 Jul 2012, at 09:48, Helen wrote:


On Monday, 2 July 2012 21:40:23 UTC+1, Adiel wrote:


Possibly. I don't quite follow though. Any chance you could post the exact HTML in the state where it fails, and the test code? Then iI'll get to the bottom of it for you.

Adrian

I know that the way the multi selects were written are not the expected, but the HTML (that is generated after the selections are made as before the 2nd and 3rd drop-downs would be empty until the previous drop-down selections are made) is as follows:
 <tr style="height: 25px">
                    <td class="formlabel">
                        <span id="ContentPlaceHolder1_ContentPlaceHolder1_lbl4" title="Single or Multi-Category events can be selected by checking the relevant box.">Category</span>
                    </td>
                    <td style="text-align: left" id='cols'>
                        <select size="4" name="ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder1$ddlCategory" multiple="multiple" id="ContentPlaceHolder1_ContentPlaceHolder1_ddlCategory" style="width:178px;">
	<option selected="selected" value="64">Candy</option>
	<option selected="selected" value="65">Chocolate</option>
	<option value="66">Coffee</option>
	<option value="67">Snacks</option>

</select>

You should select options with:

        foreach (var value in categoryarray)
{
             _eventPage.Select(value).From("ddlCategory");
}
It does work with multiple selects, I just tested it. Check is designed for checkboxes only. Have you tried this? 
I realise that for many options in the same <select> this might be a bit inefficient as it will find the "ddlCategory" element once for each option. I had not thought about this before so think I will add an overload which takes an IEnumerable<string> so you could do:
  BrowserSession.Select(categoryarray).From("ddlCategory")
And I suppose we also need this for multiple selects too:
  BrowserSession.Unselect(option).From(select)

But in the meantime can you give the Select(..).From(..) API a go and let us know how you get on?
Thanks
Adrian

Helen

unread,
Jul 10, 2012, 5:51:57 AM7/10/12
to co...@googlegroups.com
Hi Adrian,

I have found a slight problem, as although the HTML source is as I posted, the checklist is not recognised by the ID suggested.  It was why I used the long XPath:
".//*[contains(@id,'ContentPlaceHolder1_ContentPlaceHolder1_ddlBrandList')]//following-sibling::*//label[contains(text(), '" + value + "')]"

As I can't use XPath as a way to define the select list I will continue to find the element with the XPath to click.

Cheers,
Helen

Reply all
Reply to author
Forward
0 new messages