问题
I'm trying to click on an option in a select menu via:
driver.implicitly_wait(30)
driver.find_element_by_xpath("//select[option/@value='today']").click()
but it doesn't work (prints None to the terminal)
the html looks like:
<select tabindex="0" class="itc_listBox mid"><option value="oneDay">1 Day</option><option value="sevenDays">7 Days</option><option value="fourteenDays">14 Days</option><option value="oneMonth">1 Month</option><option value="sixMonth">6 Months</option><option value="oneYear">1 Year</option><option value="" disabled="disabled">————————</option><option value="today">Today</option><option value="yesterday">Yesterday</option><option value="weekToDate">Week-to-Date</option><option value="last7Days">Last 7 Days</option><option value="lastWeek">Last Week</option><option value="monthToDate">Month-to-Date</option><option value="last30Days">Last 30 Days</option><option value="customDateRange">Custom </option></select>
I'm using the Firefox webdriver and I think the html is being generated by js
回答1:
Your XPath looks wrong. Try:
"//select/option[@value='today']"
回答2:
Select day = new Select(driver.findElement(By.cssSelector(".itc_listBox")));
day.selectByVisibleText("Today");
or
day.selectByValue("today")
You can try either of the above.
来源:https://stackoverflow.com/questions/7536012/selenium-cant-find-option-form-element-by-xpath