我正在尝试按一个按钮来发送输入。我的问题是,尽管打开列表时Selenium出现在屏幕上,但Selenium似乎找不到它。
打开列表的按钮:
<input type="button" id="opensDiv" value="Actions" style="width: 137px; padding: 1px 2px;" class="ButtonOn" onclick="dropdowns.get(0).toggle();" onmouseover="dropdowns.get(0).menuenter();this.className='ButtonOn';" this.classname="ButtonOff" ; "=" ">
列表本身:
<div id="dropdown-list" class="dropdown-list" style="display: none; top: 157px; left: 1696px; width: 161px; padding-top: 24px;">
<div class="dropdown-list-wrap">
<div class="dropdown-list-item" onclick="document.getElementById('dropdown-list').style.display ='none';var w = document.getElementById('elem').contentWindow;w.eval('execute(somethingHere)');">somethingHere</div>
<div class="dropdown-list-item" onclick="document.getElementById('dropdown-list').style.display ='none';var w = document.getElementById('elem').contentWindow;w.eval('execute(somethingHere)');">somethingHere</div>
<div class="dropdown-list-item" onclick="document.getElementById('dropdown-list').style.display ='none';var w = document.getElementById('elem').contentWindow;w.eval('execute(ButtonINeed)');">iNeedThisButton</div>
<div class="dropdown-list-item" onclick="document.getElementById('dropdown-list').style.display ='none';var w = document.getElementById('elem').contentWindow;w.eval('execute(somethingHere)');">somethingHere</div>
<div class="dropdown-list-item" onclick="document.getElementById('dropdown-list').style.display ='none';var w = document.getElementById('elem').contentWindow;w.eval('execute(somethingHere)');">somethingHere</div>
<div class="dropdown-list-item" onclick="document.getElementById('dropdown-list').style.display ='none';var w = document.getElementById('elem').contentWindow;w.eval('execute(somethingHere)');">somethingHere</div>
<div class="dropdown-list-item" onclick="document.getElementById('dropdown-list').style.display ='none';var w = document.getElementById('elem').contentWindow;w.eval('execute(somethingHere)');">somethingHere</div>
<div class="dropdown-list-item" onclick="document.getElementById('dropdown-list').style.display ='none';var w = document.getElementById('elem').contentWindow;w.eval('execute(somethingHere)');">somethingHere</div>
</div>
</div>
我已经尝试使用JavaScript更改可见性:
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
((JavascriptExecutor) driver).executeScript(js, iNeedThisButton);
尝试在打开列表后仅单击它:
driver.findElement(By.xpath("//div[contains(text(),'iNeedThisButton')]")).click();
Actions builder = new Actions(driver);
builder.moveToElement(iNeedThisButton).click().build().perform();
注意:此列表位于已输入的iframe中。
编辑:这是其内部的iframe:
<iframe id="Actionsdb" style="visibility:hidden;position:absolute;width: 0px;height:162px;z-index:99;margin-left:7px;margin-top:19px;" src="plain.html" frameborder="0" scrolling="no"></iframe>
答案 0 :(得分:0)
尝试移至元素,然后使用javascript滚动一点(“ window.scrollTo(0,-15)”) 然后单击元素 python示例看起来像这样
el=driver.find_element_by_xpath("//label[contains(text(),' "+category+"')]")
webdriver.ActionChains(driver).move_to_element(el).perform()
driver.execute_script("window.scrollTo(0,-15)")
time.sleep(0.5)
driver.find_element_by_xpath("//label[contains(text(),' " + category + "')]").click()
答案 1 :(得分:0)
在这种情况下,应按以下方式使用sendKeys方法。
WebElement.sendKeys(Keys.DOWN);
WebElement.sendKeys(Keys.DOWN);
//do this until you reach your element and then do the following
WebElement.sendKeys(Key.ENTER);
答案 2 :(得分:0)
您需要切换到该iFrame,例如按ID:
driver.switchTo().frame("Actionsdb")
请注意,您之后可能需要切换回去。