I'm having trouble selecting an element from a dropdown list and interacting with it.
The xpath for the element I'm trying to select from the dropdown is:
/html/body/div[1]/div/div[1]/div[1]/div[2]/div/div/div[1]/div[2]/div[1]/div/div/div/div[2]/div/div/ul/li[2]
The dropdown window has the id rw_2_input
The dropdown list offers five options: less than 18, 18-40, 40-60, and so on. Here's what I've tried:
// Select the dropdown and click on it
const age = await driver.findElement(By.id('rw_2_input'))
await age.click()
Then,
// Select the dropdown item and click on it
const ageChoice = driver.wait(until(elementIsVisible((By.XPATH, "/html/body/div[1]/div/div[1]/div[1]/div[2]/div/div/div[1]/div[2]/div[1]/div/div/div/div[2]/div/div/ul/li[2]"))))
await ageChoice.click()
At the top of the file, I have imported these modules:
const { Builder, By, Key, util } = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome')
const expect = require('expect')
const { elementIsVisible } = require('selenium-webdriver/lib/until')
The issue I'm facing is that it says until is not defined
.
I believe there's an error in my importing process, but I am unsure of where the mistake lies. I referred to this documentation to understand the correct way to import, but I couldn't find a solution. If I try to select the element in the dropdown using
const ageChoice = await driver.findElement(By.xpath('/html/body/div[1]/div/div[1]/div[1]/div[2]/div/div/div[1]/div[2]/div[1]/div/div/div/div[2]/div/div/ul/li[2]'))
await ageChoice.click()
It returns an error stating:
ElementNotInteractableError: element not interactable
Why is it not interactable? I am confused.
* * *
***** UPDATE: *****
I managed to make some progress, but I still encounter the "Element not interactable" error: What I did was
const ageChoice = await driver.findElement(By.xpath("//li[contains(text(),'Tra 19 e 40')]"))
await ageChoice.click()
If I comment out the .click()
function everything works fine, but the option is not selected. How can I select it despite being told that it is not interactable?