I am currently in the process of automating some tests for a specific form, and I have successfully automated all steps except for selecting an option from a dropdown menu using JavaScript.
Here is my code:
const {Builder, By, Key} = require("selenium-webdriver");
async function automateSelection() {
// Launch the browser
let driver = await new Builder().forBrowser("chrome").build();
// Navigate to our application
await driver.get("https://dev.septemcompliance.com/designer/design.aspx?
c=0asrnQyA%2bharoubJy0g6zqq%2fVssaPaDM6m0yv7hD0hTwY8bXo%2bNQLRsUzDolSOAT")
// Fill in login details
await driver.findElement(By.id("TxtLogin")).sendKeys("joao")
await driver.findElement(By.id("TxtPassword")).sendKeys("010445jv")
await driver.findElement(By.id("BtnLogin")).click()
await driver.findElement(By.id("HlOpenSimulation")).click()
await driver.findElement(By.id("HlStartSimulation")).click()
await driver.findElement(By.name("inp12082")).click();
await driver.findElement(By.xpath("//*
[@id=td1secretaria_municipal]/select/option[1]")).click();
}
automateSelection()
Upon inspecting the select element that I need to automate, this is the code snippet extracted from the website:
<select label="Secretaria municipal" name="inp12082" xname="inpsecretaria_municipal"
xtype="SELECT" required="S" style="width:350px"
onchange="controlValueChange(this);salvarSecretaria($(this));atualizarSecretariasExecutivas();"
data-c="DSe28HiL3BwUi7ITIAiFKoPYC2jIQnf-1ElLrN9eVsFFzP-
O91XnU@emdmWvie5Aqx3Arj6ROWUKqAGZrCQsDjwO5geI9nuTiU9JlTlMz2hbH5D3M1D-E5loLjoTSRcU">
<option value="">Selecione</option><option value="1">SECRETARIA 1</option>
</select>