I'm attempting to programmatically select an item in a CSS dropdown using Selenium, specifically on the Google hotel review page. On this particular page here, I am trying to select the most recent reviews instead of the default "most useful" sorting.
Based on my research, I have attempted to use the following code:
Select select = new Select(driver.findElement(By.xpath("//*[@id=\"gsr\"]/g-lightbox/div[2]/div[3]/div/div/div/div[1]/div[3]/div[2]/g-dropdown-menu/g-popup/div[2]/g-menu")));
select.deselectByIndex(1);
However, I encountered an exception (
org.openqa.selenium.support.ui.UnexpectedTagNameException
) which states:
Element should have been "select" but was "g-dropdown-menu"
My question is, is there a way to simulate a click on a CSS dropdown element like this using Selenium web driver?