JAVA - Wie man xpath in Selen verwendet
Ich habe diesen HTML-Code:
<code><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> </code>
und ich muss das WebElement auswählen, das durch das Tag identifiziert wirdoption
mit textAuto
. Ich versuche eine Lösung wie:
<code>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(); </code>
aber jeder gibt mir:
<code>Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"/select[@id=category]/option[@id=cat2]"} ( and other xpath i tried) Command duration or timeout: 1.52 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html </code>
Was ist die richtige Syntax? kann mir jemand helfen?