Java Code Examples for org.openqa.selenium.WebElement#equals()
The following examples show how to use
org.openqa.selenium.WebElement#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomConditions.java From opentest with MIT License | 6 votes |
/** * Returns an ExpectedCondition instance that waits until an element becomes * the active (in-focus) element. */ public static ExpectedCondition<Boolean> elementToBeActive(final WebElement element) { return new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driver) { try { if (element.equals((driver.switchTo().activeElement()))) { return true; } else { return false; } } catch (Exception ex) { return false; } } @Override public String toString() { return "element to be active (in focus): " + element.toString(); } }; }
Example 2
Source File: CustomConditions.java From opentest with MIT License | 6 votes |
/** * Returns an ExpectedCondition instance that waits until an element is not * active (in focus). */ public static ExpectedCondition<Boolean> elementToNotBeActive(final WebElement element) { return new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driver) { try { if (!element.equals((driver.switchTo().activeElement()))) { return true; } else { return false; } } catch (Exception ex) { return false; } } @Override public String toString() { return "element to not be active (in focus): " + element.toString(); } }; }
Example 3
Source File: SeleniumElement.java From xframium-java with GNU General Public License v3.0 | 6 votes |
@Override protected boolean _isFocused() { WebElement webElement = (WebElement) getElement(); boolean returnValue = false; if (getNativeDriver() instanceof AppiumDriver) { String focusValue = getAttribute("focused"); if (focusValue != null) returnValue = Boolean.parseBoolean(focusValue); } else if (getNativeDriver() instanceof RemoteWebDriver) returnValue = webElement.equals(getWebDriver().switchTo().activeElement()); if (returnValue) getActionProvider().getSupportedTimers((DeviceWebDriver) getWebDriver(), getExecutionContext().getTimerName(), getExecutionContext(), null); return returnValue; }
Example 4
Source File: ElementEquality.java From selenium with Apache License 2.0 | 6 votes |
@Override public Boolean call() { WebElement one = getElement(); WebElement two = getKnownElements().get(otherId); // Unwrap the elements, if necessary if (one instanceof WrapsElement) { one = ((WrapsElement) one).getWrappedElement(); } if (two instanceof KnownElements.ProxiedElement) { two = ((KnownElements.ProxiedElement) two).getWrappedElement(); } return one.equals(two); }
Example 5
Source File: AppPage.java From teammates with GNU General Public License v2.0 | 5 votes |
/** * Checks if the midpoint of an element is covered by any other element. * @return true if element is covered, false otherwise. */ public boolean isElementCovered(WebElement element) { int x = element.getLocation().x + element.getSize().width / 2; int y = element.getLocation().y + element.getSize().height / 2; WebElement topElem = (WebElement) executeScript("return document.elementFromPoint(" + x + "," + y + ");"); return !topElem.equals(element); }
Example 6
Source File: AttachExistingElementIT.java From flow with Apache License 2.0 | 4 votes |
@Test public void attachExistingElement() { open(); // attach label findElement(By.id("attach-label")).click(); Assert.assertTrue(isElementPresent(By.id("label"))); WebElement label = findElement(By.id("label")); Assert.assertEquals("label", label.getTagName().toLowerCase(Locale.ENGLISH)); WebElement parentDiv = findElement(By.id("root-div")); List<WebElement> children = parentDiv .findElements(By.xpath("./child::*")); boolean labelIsFoundAsChild = false; WebElement removeButton = null; for (int i = 0; i < children.size(); i++) { WebElement child = children.get(i); if (child.equals(label)) { labelIsFoundAsChild = true; WebElement attachButton = children.get(i + 1); Assert.assertEquals("The first inserted component after " + "attached label has wrong index on the client side", "attach-populated-label", attachButton.getAttribute("id")); removeButton = children.get(i + 2); Assert.assertEquals("The second inserted component after " + "attached label has wrong index on the client side", "remove-self", removeButton.getAttribute("id")); break; } } Assert.assertTrue( "The attached label is not found as a child of its parent", labelIsFoundAsChild); removeButton.click(); Assert.assertFalse(isElementPresent(By.id("remove-self"))); // attach existing server-side element findElement(By.id("attach-populated-label")).click(); Assert.assertEquals("already-populated", label.getAttribute("class")); // attach header element findElement(By.id("attach-header")).click(); Assert.assertTrue(isElementPresent(By.id("header"))); Assert.assertEquals("h1", findElement(By.id("header")).getTagName() .toLowerCase(Locale.ENGLISH)); // attach a child in the shadow root of the div findElement(By.id("attach-label-inshadow")).click(); LabelElement labelInShadow = $(DivElement.class) .id("element-with-shadow").$(LabelElement.class) .id("label-in-shadow"); Assert.assertEquals("label", labelInShadow.getTagName().toLowerCase(Locale.ENGLISH)); // Try to attach non-existing element findElement(By.id("non-existing-element")).click(); Assert.assertTrue(isElementPresent(By.id("non-existing-element"))); }
Example 7
Source File: InstructorFeedbackEditPage.java From teammates with GNU General Public License v2.0 | 4 votes |
public boolean isRubricSubQuestionBoxFocused(int qnNumber, int subQnIndex) { WebElement subQnBox = getRubricSubQuestionBox(qnNumber, subQnIndex); return subQnBox.equals(browser.driver.switchTo().activeElement()); }
Example 8
Source File: InstructorFeedbackEditPage.java From teammates with GNU General Public License v2.0 | 4 votes |
public boolean isRubricWeightBoxFocused(int qnNumber, int subQnIndex, int choiceIndex) { WebElement weightBox = getRubricWeightBox(qnNumber, subQnIndex, choiceIndex); return weightBox.equals(browser.driver.switchTo().activeElement()); }
Example 9
Source File: InstructorFeedbackEditPage.java From teammates with GNU General Public License v2.0 | 4 votes |
public boolean isMcqWeightBoxFocused(int qnNumber, int choiceIndex) { WebElement weightBox = getMcqWeightBox(qnNumber, choiceIndex); return weightBox.equals(browser.driver.switchTo().activeElement()); }
Example 10
Source File: InstructorFeedbackEditPage.java From teammates with GNU General Public License v2.0 | 4 votes |
public boolean isMcqOtherWeightBoxFocused(int qnNumber) { WebElement weightBox = getMcqOtherWeightBox(qnNumber); return weightBox.equals(browser.driver.switchTo().activeElement()); }
Example 11
Source File: InstructorFeedbackEditPage.java From teammates with GNU General Public License v2.0 | 4 votes |
public boolean isMsqWeightBoxFocused(int qnNumber, int choiceIndex) { WebElement weightBox = getMsqWeightBox(qnNumber, choiceIndex); return weightBox.equals(browser.driver.switchTo().activeElement()); }
Example 12
Source File: InstructorFeedbackEditPage.java From teammates with GNU General Public License v2.0 | 4 votes |
public boolean isMsqOtherWeightBoxFocused(int qnNumber) { WebElement weightBox = getMsqOtherWeightBox(qnNumber); return weightBox.equals(browser.driver.switchTo().activeElement()); }
Example 13
Source File: AppPage.java From teammates with GNU General Public License v2.0 | 3 votes |
/** * Selects the option by visible text and returns whether the dropdown value has changed. * * @throws AssertionError if the selected option is not the one we wanted to select * * @see Select#selectByVisibleText(String) */ boolean selectDropdownByVisibleValue(WebElement element, String text) { Select select = new Select(element); WebElement originalSelectedOption = select.getFirstSelectedOption(); select.selectByVisibleText(text); WebElement newSelectedOption = select.getFirstSelectedOption(); assertEquals(text, newSelectedOption.getText().trim()); return !newSelectedOption.equals(originalSelectedOption); }
Example 14
Source File: AppPage.java From teammates with GNU General Public License v2.0 | 3 votes |
/** * Selects the option by value and returns whether the dropdown value has changed. * * @throws AssertionError if the selected option is not the one we wanted to select * * @see Select#selectByValue(String) */ boolean selectDropdownByActualValue(WebElement element, String value) { Select select = new Select(element); WebElement originalSelectedOption = select.getFirstSelectedOption(); select.selectByValue(value); WebElement newSelectedOption = select.getFirstSelectedOption(); assertEquals(value, newSelectedOption.getAttribute("value")); return !newSelectedOption.equals(originalSelectedOption); }