Rajagopalan
Rajagopalan

Reputation: 6064

The dropdown list on this website shows a varying number of options when I open it manually compared to when I open it through automation

I'm attempting to automate processes on https://ttsreader.com/legacy/. However, I've noticed that the site presents different options when opened manually compared to when accessed through automation. Specifically, when using automation, only a limited number of options are displayed, as indicated below.

enter image description here

However, when opened manually, the site displays 320 language options. I'm perplexed by this inconsistency. I've attempted to reference the same profile that Edge is using, yet it still shows only 6 options, as depicted in the earlier image. In contrast, manually opening the site, as illustrated below, reveals a multitude of options.

enter image description here

Can anybody guide me why this difference?

Upvotes: 0

Views: 149

Answers (1)

Ronen Rabinovici
Ronen Rabinovici

Reputation: 9092

Thank you, I tried the following code and it works as expected for me. Maybe the 'magic' is to wait a few seconds before the code executes so that the whole page - and specifically the voices have time to load. Here's my test code:

const {Builder, Browser, Select, By} = require('selenium-webdriver');
const delay = ms => new Promise(res => setTimeout(res, ms));

(async function helloSelenium() {
  let driver = await new Builder().forBrowser(Browser.CHROME).build();

  await driver.get('https://ttsreader.com/legacy/');
  await delay(5000); // Wait 5 seconds - so that voices can load.

  const selectElement = await driver.findElement(By.id('select_language'))
  const select = new Select(selectElement)

  select.getOptions().then(arr=>{
    console.log(arr.length);
  })

  await select.selectByValue('Sandy (French (France))')

  // Do not quit, so we can visually see the selected option exists.
  // await driver.quit();
})();

Here's my package.json:

{
    "name": "ttsreader-test",
    "version": "1.0.0",
    "scripts": {
        "test": "npx mocha src/hello.js --timeout 60000"
    },
    "author": "Ronen Rabinovici",
    "license": "Apache-2.0",
    "dependencies": {
        "assert": "^2.1.0",
        "selenium-webdriver": "^4.18.1"
    },
    "devDependencies": {
        "mocha": "^10.2.0"
    }
}

Upvotes: 0

Related Questions