'I can not select list item in selenium

What is the script for selenium in li tag. I used Xpath in selenium.

driver.findElement(By.xpath(" //*[@id='select2-product_cat-container']")).click() ;

But it is not working.

This image is web code Sample



Solution 1:[1]

The id which is present on the html can be dynamic, so you can use the text in xpath to find the element.
You can click on it like:

driver.findElement(By.xpath("//li[text()='Uncategorized']")).click(); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sameer Arora