I'm using TestCafe 1.8.1 and have a slightly different case than the documentation at https://devexpress.github.io/testcafe/documentation/recipes/test-select-elements.html - my problem is that the example assumes the value
of an <option>
and its text content will be the same, and in my case, the value
is a very unpredictable value.
I can select an item in the dropdown without trouble, using .withText(value)
to filter the options, and .click(item)
to select it. However, my app then refreshes the page, and ought to re-select the relevant item as it loads up. This is not working and I want to test for it.
So I might have options in the select like:
<select id="foo">
<option value="1234">100x100</option>
<option value="5432">200x100</option>
<option value="9999">100x200</option>
</select>
Obviously, if I test with .expect(citySelect.value).eql('London');
as in the docs it'll fail because the values are nothing like the text content e.g. having clicked '200x100' in the dropdown the value becomes "5432".
Do I need to use a ClientFunction
to get the text of the selected item? I understand it's quite awkward passing data into a ClientFunction, would I need to pass the id
of the select so the ClientFunction can getElementById
to find the select and retrieve it's selected option's text content? It all sounds like the wrong way to be doing things.