如何对 headers 很少的下拉列表执行 selectByValue?
How to perform selectByValue for a dropdown with few headers?
通常我不得不处理 drop-down 而没有 headers/headlines,所以我只是这样执行它们:
val selectDocTypeDropDown = new Select(driver.findElement(By.id("admin-select-page")))
selectDocTypeDropDown.selectByValue("245")
但现在我需要处理 drop-down 和 headers,它的 HTML/CSS 看起来像这样:
但是它不接受我上面做的两行。 select按值这里应该怎么办?
// find the select
val selectDocTypeDropDown = driver.findElement(By.id("admin-select-page"))
// find the option to be selected
val optionToSelect = driver.findElement(By.xpath("//select[@id='admin-select-page']//option[@value='245']"))
selectDocTypeDropDown.click()
optionToSelect.click()
我更喜欢找到 select 和 select 一起编辑的选项,因为单击 select 然后找到选项有时可能会导致 select 框失去焦点。
通常我不得不处理 drop-down 而没有 headers/headlines,所以我只是这样执行它们:
val selectDocTypeDropDown = new Select(driver.findElement(By.id("admin-select-page")))
selectDocTypeDropDown.selectByValue("245")
但现在我需要处理 drop-down 和 headers,它的 HTML/CSS 看起来像这样:
但是它不接受我上面做的两行。 select按值这里应该怎么办?
// find the select
val selectDocTypeDropDown = driver.findElement(By.id("admin-select-page"))
// find the option to be selected
val optionToSelect = driver.findElement(By.xpath("//select[@id='admin-select-page']//option[@value='245']"))
selectDocTypeDropDown.click()
optionToSelect.click()
我更喜欢找到 select 和 select 一起编辑的选项,因为单击 select 然后找到选项有时可能会导致 select 框失去焦点。