由于某种原因,单击特定的按钮元素时出现奇怪的问题。
元素HTML如下:
<button type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">Search</span></button>
我的代码在Chrome浏览器中工作正常,并且Firefox浏览器出现问题。尽管控制台输出显示单击了Element,但是我看不到在自动执行时导致应用程序失败的反映在应用程序中。
我执行以下操作:
public String clickAt(String identifier) {
currentKeywordLog = " Click on element: " +identifier;
APP_LOGS.debug(" Click on element: " +identifier);
try {
Actions action = new Actions(driver);
WebElement webElement = objectLocator(identifier);
Thread.sleep(800);
String scrollElementIntoMiddle = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);"
+ "var elementTop = arguments[0].getBoundingClientRect().top;"
+ "window.scrollBy(0, elementTop-(viewPortHeight/2));";
((JavascriptExecutor) driver).executeScript(scrollElementIntoMiddle, webElement);
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(false);",webElement);
Thread.sleep(1000);
if (webElement.isDisplayed() && webElement.isEnabled()) {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(webElement));
Thread.sleep(1000);
action.moveToElement(webElement).click(webElement).perform();
//webElement.click();
//((JavascriptExecutor) driver).executeScript("arguments[0].click();",webElement);
}
} catch (Exception e) {
currentKeywordErrorMessage = e.getMessage();
return Constants.KEYWORD_FAIL + " --> " + ApplicationTest.currentTestSuite + " - " +ApplicationTest.currentTestCaseName+ " - " + ApplicationTest.currentTestStepID +" , Reason:- " + " Unable to click, " + e.getMessage();
}
return Constants.KEYWORD_PASS;
}
我有我的等待时间,检查元素是否可单击,尝试使用javascript执行程序单击,尝试使用其他定位器(css,xpath)。我仍然有这个问题,不确定可能是什么问题。使用最新版本的Selenium,gecko和firefox浏览器。
有什么建议吗?
谢谢 纳真德拉