Java 按值选择元素
我尝试自动化的网站有一些单选按钮,如下所示:Java 按值选择元素,java,selenium,selenium-webdriver,css-selectors,Java,Selenium,Selenium Webdriver,Css Selectors,我尝试自动化的网站有一些单选按钮,如下所示: <input type="radio" name="outputFormat" value="quicken" checked="checked"> <input type="radio" name="outputFormat" value="xls"> <input type="radio" name="outputFormat" value="csv" checked="on"> <input type=
<input type="radio" name="outputFormat" value="quicken" checked="checked">
<input type="radio" name="outputFormat" value="xls">
<input type="radio" name="outputFormat" value="csv" checked="on">
<input type="radio" name="outputFormat" value="quickbooks">
driver.findElement(By.cssSelector("value=\"csv\"")).click();
但是,这给了我一个无效的选择器错误。您需要修复CSS选择器:
driver.findElement(By.cssSelector("value=\"csv\"")).click();
driver.findElement(By.cssSelector("input[value=csv]")).click();
请注意,选择器的主要问题是属性检查缺少[
和]
。在这种情况下也没有必要这样做[value=csv]
也可以,但最好明确您要定位的元素
driver.findElement(By.cssSelector("value=\"csv\"")).click();