Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
Not able to select a value from drop down using Index in Testcafe

Below is my code. I am able to access and select the item from drop down from a browser console using

  '''document.querySelector('#__next > div > main > div.Home_toolbar__JY_RL > 
  div.Home_deviceControls__nQw4V > select:nth-child(2)').selectedIndex = 3'''

But from test in testcafe from below code -

''test('Select each available Audio input device', async (browser) => {
await browser.wait(6000);
let audioDevices = Selector('#__next > div > main > 
div.Home_toolbar__JY_RL > div.Home_deviceControls__nQw4V > 
select:nth-child(2)'
).selectedIndex = 3
await browser.expect(audioDevicescount.selectedIndex).eql(3);
});'''

Below is the error I get -

TypeError: Cannot set property selectedIndex of function __$$clientFunction$$() { const testRun = builder._getTestRun(); const callsite...... } which has only a getter

I tried using client function, but could not pass the selectedIndex value.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You cannot set the 'selectedIndex' property using the Selector, since the Selector is created for element querying. To modify the element state on the client side, use the ClientFunctions mechanism. I created a sample that demonstrates how to set selectedIndex using the ClientFunction. Please see the code below:

<select>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>
import { Selector, ClientFunction } from 'testcafe';

fixture `f`
    .page `index.html`;

const select = Selector('select');

const setSelectedIndex = ClientFunction(index => {
    select().selectedIndex = index;
}, { dependencies: { select } });

test(`t`, async t => {
    await setSelectedIndex(2);

    await t.expect(select.selectedIndex).eql(2);
});

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda