一般的geb和自动化测试新手。我在自动点击和拖动页面上的元素方面遇到了麻烦。我已经阅读了geb的书并发现了Action类,并编写了一些非常程序化的代码来测试它。我可能误解了动作类的运作方式,因为它似乎没有执行任务。它编译没有任何问题,测试仍然运行而不会丢失任何错误。我尝试拖动的网页元素确实存在,我确定它是正确的。
<div id="enquireForm:j_id_t_3_1_u:sliderframe" class="ets-nicecaptcha-slider ets-nicecaptcha-button-style ui-button-gradient">
<span id="enquireForm:j_id_t_3_1_u:slidedrop" class="ets-nicecaptcha-drop ets-nicecaptcha-button-style ui-droppable">
</span>
<div id="enquireForm:j_id_t_3_1_u:sliderbutton" class="ets-nicecaptcha-slider-button ets-nicecaptcha-button-style ui-draggable ui-draggable-handle" style="position: relative;">
</div>
</div>
void slideToSubmit(){
WebElement slider = driver.findElement(By.className("ets-nicecaptcha-slider-button"))
Actions action = new Actions(driver)
action.perform()
action = action.clickAndHold(slider)
action.perform()
action = action.moveByOffset(500,0)
action.perform()
action = action.release(slider)
action.perform()
}
答案 0 :(得分:0)
类名中的空格可能是个问题。试试
WebElement slider = driver.findElement(By.cssSelector("div[class='ets-nicecaptcha-slider-button ets-nicecaptcha-button-style ui-draggable ui-draggable-handle']"))
或直接尝试而不使用By
类
def browser = new Browser(driver: new FirefoxDriver()) // or whichever driver you use
browser.go "www.url.com"
browser.$("div.ets-nicecaptcha-slider-button.ets-nicecaptcha-button-style.ui-draggable.ui-draggable-handle")
答案 1 :(得分:0)
如果你正在使用Geb,那么你应该使用interact()
method来简化这样的事情:
interact {
clickAndHold($(".ets-nicecaptcha-slider-button"))
moveByOffset(500,0)
release()
}