Skip to content
Advertisement

How to select an option from a list (not in dropdown) in Selenium Java

I am trying to select an option(not from the dropdown) and then click on the button. The problem is I cannot find any class name, id or name or any selector to find that element.List

I tried "By.className="device pcclient selected" but an error occurs “Compound class names not permitted”. How can I select an option from R1, R2, R3 and then click on the button.

Advertisement

Answer

You get the error “Compound class names not permitted” when there are spaces in the class name and you try to find that element by using the className method. For more info on the error, you can refer this link.

You can try finding the desired element by xpath and click on it as shown below:

//Clicking R1
driver.findElement(By.xpath("//li[@class='device pcclient']/a[contains(text(),'R1')]").click();

//Clicking R2
driver.findElement(By.xpath("//li[@class='device pcclient']/a[contains(text(),'R2')]").click();

//Clicking R3
driver.findElement(By.xpath("//li[@class='device pcclient']/a[contains(text(),'R3')]").click();
Advertisement