我写了这段代码:
try{
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();
robot.delay(500);
element.click();
}catch(WebDriverException clickIntercepted){
robot.keyPress(KeyEvent.VK_PAGE_DOWN);
robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
element.click();
}
元素“ element”位于视口外部,但是当我移至该元素时,页面将滚动直到该元素位于视口中,但它位于页脚后面,因此当我尝试单击它时,点击拦截的异常。要绕过此操作,请按向下翻页键并松开,问题是,只有当我的浏览器位于屏幕顶部并且正在执行其他操作时,它才起作用。 不使用javascriptexecutor或按向下翻页键,是否可以滚动直到页脚未覆盖该元素? 我也尝试过
moveToElement(element,x,y)
但与moveToElement(element)相同
这是页面底部的HTML代码:
<div id="bottom">
<div id="errorboxcomponent" class="">
<div id="decisionTB" style="display:none;">
<div id="errorBoxDecision" class="errorBox TBfixedPosition">
<div class="head"><h4 id="errorBoxDecisionHead">-</h4></div>
<div class="middle">
<span id="errorBoxDecisionContent">-</span>
<div class="response">
<div style="float:left; width:180px;">
<a href="javascript:void(0);" class="yes"><span id="errorBoxDecisionYes">.</span></a>
</div>
<div style="float:left; width:180px;">
<a href="javascript:void(0);" class="no"><span id="errorBoxDecisionNo">.</span></a>
</div>
<br class="clearfloat">
</div>
</div>
<div class="foot"></div>
</div>
</div>
<div id="fadeBox" class="fadeBox fixedPostion" style="display:none;">
<div>
<span id="fadeBoxStyle" class="success"></span>
<p id="fadeBoxContent"></p>
</div>
</div>
<div id="notifyTB" style="display:none;">
<div id="errorBoxNotify" class="errorBox TBfixedPosition">
<div class="head"><h4 id="errorBoxNotifyHead">-</h4></div>
<div class="middle">
<span id="errorBoxNotifyContent">-</span>
<div class="response">
<div>
<a href="javascript:void(0);" class="ok">
<span id="errorBoxNotifyOk">.</span>
</a>
</div>
<br class="clearfloat">
</div>
</div>
<div class="foot"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
initBuffBar();
initIndex();
</script>
<div id="siteFooter">
<div class="content" style="font-size:10px">
<div class="fleft textLeft">
<a class="tooltip js_hideTipOnMobile overlay" href="URL;component=changelog&ajax=1" data-overlay-class="popupWidthFixed" data-overlay-iframe="true" data-iframe-width="680" data-overlay-title="Note di versione" title="Note di versione">7.2.1</a>
<a class="homeLink" href="URL" target="_blank">...</a>
</div>
<div class="fright textRight">
<a href="URL" target="_blank">Help</a>|
<a href="URL" target="_blank">Forum</a>|
<a class="overlay" href="URL;component=rules&ajax=1" data-overlay-iframe="true" data-iframe-width="450" data-overlay-title="Regole">Rules</a>|
<a href="URL;product=..." target="_blank">Contatti</a>
</div>
</div>
</div>
这是元素:
<img src="https://g1.ge.gsv.net/cdn9d/8e0e60340445budse18a1804b42f179.gif" width="16" height="16" alt="moon" class="icon-moon">
页脚固定在DOM的底部,因此元素位于它的后面。
在此处,您可以在moveToElement(element)之后的页脚后面看到“ moon”元素,就像标记的元素一样
答案 0 :(得分:0)
尝试以下解决方案:
df = pd.DataFrame({'date': {880551: '2015-07-06 04:00:00', 880552: '2015-07-06 04:02:00',880553: '2015-07-06 04:03:00', 880554: '2015-07-06 04:04:00', 880555: '2015-07-06 04:05:00'},
'open': {880551: 125.00, 880552: 125.36,880553: 125.34, 880554: 125.08, 880555: 125.12},
'high': {880551: 125.00, 880552: 125.36,880553: 125.34, 880554: 125.11, 880555: 125.12},
'low': {880551: 125.00, 880552: 125.32,880553: 125.21, 880554: 125.05, 880555: 125.12},
'close': {880551: 125.00, 880552: 125.32,880553: 125.21, 880554: 125.05, 880555: 125.12},
'volume': {880551: 141, 880552: 200,880553: 750, 880554: 17451, 880555: 1000},
},
)
df.head()
date open high low close volume
880551 2015-07-06 04:00:00 125.00 125.00 125.00 125.00 141
880552 2015-07-06 04:02:00 125.36 125.36 125.32 125.32 200
880553 2015-07-06 04:03:00 125.34 125.34 125.21 125.21 750
880554 2015-07-06 04:04:00 125.08 125.11 125.05 125.05 17451
880555 2015-07-06 04:05:00 125.12 125.12 125.12 125.12 1000
from datetime import time
start_first = time(9, 30)
end_first = time(11, 59)
start_second = time(0, 00)
end_second = time(4,00)
df['date'] = pd.to_datetime(df['date'])
df= df[(df['date'].dt.time.between(start_first, end_first)) | (df['date'].dt.time.between(start_second, end_second))]
df
date open high low close volume
880551 2015-07-06 04:00:00 125.0 125.0 125.0 125.0 141
答案 1 :(得分:0)
您可以使用JavascriptExecutor
click来单击元素,因为JavascriptExecutor
click方法直接与dom结构交互。
您可以这样做:
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//img[@alt='moon' and @class='icon-moon']")));
js.executeScript("arguments[0].click();", element);