我是Selenium WebDriver测试的新手,我尝试在工作中使用它。我尝试了许多选择器,xpaths等的组合,但我无法移过它。我也在stackoverflow上搜索了很多类似的主题,可惜没有预期的结果。我需要的是能够点击“无服务”按钮(一个href)。当我尝试时,我不断收到错误,说明此元素不可见。当我尝试使用“等待”处理此错误时,我不断收到另一个错误“预期的条件失败:等待元素的可见性...”。我究竟做错了什么?Selenium WebDriver Java - 元素不可见
我的代码:
WebDriverWait waitWait = new WebDriverWait(driver, 40);
waitWait.until(ExpectedConditions.visibilityOfElementLocated(By.className("withoutService")));
WebElement x = driver.findElement(By.className("withoutService"));
x.click();
,也是一个HTML代码片段从网页:
<div id="fancybox-outer">
<div id="fancybox-content">
<div style="width:auto;position:relative;">
<div id="serviceReminder" style="width: 765px">
<form id="serviceReminderFrom" method="post">
<div class="homeMessage">
<div class="innerMessage">
<input type="hidden" id="serviceToAddReminderFromAction" name="F_ACTION" value="">
<input type="hidden" id="itemsWithServices" name="itemsWithServices" value="">
<input type="hidden" name="eventTypeName" value="Something">
<div class="ServicesDelivery"><span class="disable-button"></span>
<a href="javaScript:void(0);" rel="3" class="withoutService btn btn-fourth" onclick="registerButtonClickOnPopup('NO SERVICE'); setTimeout(function(){registerButtonClickOnPopup('NO SERVICE');},400);">NO SERVICE</a>
<a href="javascript:void(0)" rel="1" class="next js-tooltip btn btn-second" onclick="registerButtonClickOnPopup('ADD SERVICE'); setTimeout(function(){registerButtonClickOnPopup('ADD SERVICE');},400);">ADD SERVICE</a>
<div class="none">
</div>
<div class="clear"></div>
</div>
</div>
</div>
</form>
</div></div></div><a id="fancybox-close" style="display: inline;"></a><div id="fancybox-title" class="" style="display: none;">
</div><a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a><a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a></div>
你正在寻找的元素包含在“隐藏”的输入内,你在测试中做了些什么来使输入不被隐藏? – Josh
@Josh,不,它不是隐藏的“输入”的一部分。 AFAIK,'input'元素只能包含属性,而不能包含其他节点。 – Andersson