在selenium with java中,如何选择当鼠标悬停在按钮上时可见的按钮内的隐藏下拉列表
我正在写一个selenium程序来解析好市多网页上的评论。 我想对评论进行排序,并一次获取一页已排序的评论。 问题在于,选择下拉列表隐藏在按钮元素下,只有当鼠标悬停在其上时才可见。我能够访问按钮,但无法访问select元素 DOM:在selenium with java中,如何选择当鼠标悬停在按钮上时可见的按钮内的隐藏下拉列表,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我正在写一个selenium程序来解析好市多网页上的评论。 我想对评论进行排序,并一次获取一页已排序的评论。 问题在于,选择下拉列表隐藏在按钮元素下,只有当鼠标悬停在其上时才可见。我能够访问按钮,但无法访问select元素 DOM: <div class="bv-dropdown"> <div class="bv-dropdown-target" role="menu"> <span id="bv-dropdown-select-reviews" cla
<div class="bv-dropdown">
<div class="bv-dropdown-target" role="menu">
<span id="bv-dropdown-select-reviews" class="bv-dropdown-label"> Sort by: </span>
<button type="button" class="bv-focusable" aria-haspopup="true" aria-expanded="false" role="menuitem" aria-labelledby="bv-dropdown-select-reviews bv-dropdown-title-reviews">
<span id="bv-dropdown-title-reviews" class="bv-dropdown-title"> Most Relevant </span>
<span class="bv-dropdown-arrow" aria-hidden="true" role="presentation"> ▼ </span>
<span class="bv-off-screen">Menu</span>
</button> </div>
<select class="bv-select-cleanslate bv-dropdown-select" aria-hidden="true" aria-labelledby="bv-dropdown-select-reviews" tabindex="-1">
<option value="relevancy" selected=""> Most Relevant </option>
<option value="mostHelpful"> Most Helpful </option>
<option value="positive"> Highest to Lowest Rating </option>
<option value="negative"> Lowest to Highest Rating </option>
<option value="mostRecent"> Most Recent </option>
</select>
</div>
WebElement sortSelection = driver.findElement(By.xpath("//div[@class='bv-dropdown']"));
Actions action = new Actions(driver);
action.moveToElement(sortSelection).moveToElement(driver.findElement(By.xpath("//select[@class='bv-select-cleanslate bv-dropdown-select']/option[@value = 'mostRecent']"))).click().build().perform();
请帮忙 这与下面的答案不同吗?是的,主要问题是下拉列表是隐藏的,我的代码无法访问元素