Below is the HTML code I am testing and I have to click on the option having text "Auto".
<select name="category" id="category">
<option value="0">«Seleziona la categoria»</option>
<option value='1' style='background-color:#ddd' disabled="disabled" id='cat1' >-- VEICOLI --</option>
<option value='2' id='cat2' >Auto</option>
</select>
I've tried all the possible codes below.
d.findElement(By.xpath("/select[@id=category]/option[@id=cat2]")).click();
d.findElement(By.xpath("/select[@id=category]/option[text()='Auto']")).click();
d.findElement(By.xpath("//select[@id=category]/option[Auto]")).click();
But still I get no such element exception when tries with all these XPaths.
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"/select[@id=category]/option[@id=cat2]"}
Which of these is the correct syntax? can someone help me? Help plz!