I am trying to set a select option of a select. I do so by the following:
document.getElementById('identifier').value = 'xy'
I see that the option xy
is being selected in the dropdown UI when I execute above code - however, another value on the website does not update even though it should. When I click on the dropdown option manually it works perfectly fine.
I assume I need to add some sort of eventlistener or update callback. Any pointers here? Thanks.
EDIT
Concrete Example:
See [this website][1] here holding the two dropdowns.
I get the first dropdown like so:
let runTimeElement = document.querySelector('#laufzeit')
Then I want to set the value to say 12 months:
runTimeElement.value = "12 Monate"
You can see how the UI adapts, however the price does not. It should change. When you click the dropdowns by hand it does change though.
Thanks!
EDIT 2
I tried page.select() before. I loop through two arrays containing the string values of both dropdowns and try to grab the price:
for (const runTimeElement of runTimeElements.slice(1))
{
await page.select('#laufzeit', runTimeElement)
for (const kmElement of kmElements.slice(1))
{
await page.select('#kilometerparket', kmElement)
await page.waitForSelector(CONSTANTS.SELECTOR_CONTRACT_PRICE)
let priceElement = await page.$(CONSTANTS.SELECTOR_CONTRACT_PRICE)
let priceValue = await page.evaluate(el => el.textContent, priceElement)
console.log(runTimeElement, kmElement, priceValue)
contractRuntimes.push({
contract_runtime: getCleanNumber(runTimeElement),
monthly_price: getCleanNumber(priceValue.split(",")[0]),
monthly_kms: getCleanNumber(kmElement),
})
}
}
The issue is that the price does not update. It always stays at the default price and doesnt move as the values change.
E.g. currently it would output:
[
{ contract_runtime: 6, monthly_price: 259, monthly_kms: 750 },
{ contract_runtime: 6, monthly_price: 259, monthly_kms: 1000 },
{ contract_runtime: 6, monthly_price: 259, monthly_kms: 1250 },
{ contract_runtime: 12, monthly_price: 259, monthly_kms: 750 },
{ contract_runtime: 12, monthly_price: 259, monthly_kms: 1000 },
{ contract_runtime: 12, monthly_price: 259, monthly_kms: 1250 }
]