List of usage examples for org.openqa.selenium.remote RemoteWebElement getAttribute
@Override
public String getAttribute(String name)
From source file:marmotinni.DispatchMouseEvent.java
License:Apache License
/** * Dispatch a mouse event// www . j a va 2s . c o m */ @Override protected void doStep() { Long x; Long y; if (hasLocal) { StringBuilder script = new StringBuilder(); insertTargetScript(script, target); script.append("return target.element.offsetLeft"); if (TestStep.showScripts) System.out.println(script); x = (Long) ((JavascriptExecutor) webDriver).executeScript(script.toString()); script = new StringBuilder(); insertTargetScript(script, target); script.append("return target.element.offsetTop"); if (TestStep.showScripts) System.out.println(script); y = (Long) ((JavascriptExecutor) webDriver).executeScript(script.toString()); x += localX; y += localY; } else { x = stageX; y = stageY; } // find top-most element StringBuilder script = new StringBuilder(); script.append("var all = document.all;"); script.append("var n = all.length;"); script.append("for(var i=n-1;i>=0;i--) { "); script.append(" var e = all[i];"); script.append(" if (" + x + " >= e.offsetLeft && " + x + " <= e.offsetLeft + e.offsetWidth && " + y + " >= e.offsetTop && " + y + " <= e.offsetTop + e.offsetHeight) {"); script.append(" if (!e.id) e.id = Math.random().toString();"); script.append(" return e;"); script.append(" }"); script.append("};"); script.append("return null;"); if (TestStep.showScripts) System.out.println(script); RemoteWebElement mouseTarget = (RemoteWebElement) ((JavascriptExecutor) webDriver) .executeScript(script.toString()); //System.out.println("mouseTarget: " + mouseTarget.getTagName() + " " + mouseTarget.getAttribute("id")); String actualId = mouseTarget.getAttribute("id"); script = new StringBuilder(); script.append("var e = document.createEvent('MouseEvent');"); script.append("e.initMouseEvent(\"" + type + "\", true, false, window, " + delta + ", " + x + ", " + y + ", " + localX + ", " + localY + ", " + ctrlKey + ", false, " + shiftKey + ", false, " + type.equals("mouseDown") + ", " + relatedObject + ");"); script.append("document.getElementById('" + actualId + "').dispatchEvent(e);"); if (TestStep.showScripts) System.out.println(script); try { ((JavascriptExecutor) webDriver).executeScript(script.toString()); } catch (Exception e1) { TestOutput.logResult("Exception thrown in DispatchMouseEvent."); testResult.doFail(e1.getMessage()); } }
From source file:org.richfaces.tests.metamer.ftest.richEditor.TestEditorJSApi.java
License:Open Source License
@Test
@Templates(value = { "plain" })
public void testGetInput() {
RemoteWebElement textArea = Utils.invokeRichFacesJSAPIFunction(getEditorRootElement(), "getInput()");
assertEquals(textArea.getAttribute("id"), getEditorTextArea().getAttribute("id"));
}