Skip to content

Instantly share code, notes, and snippets.

@ck1125
Created June 30, 2011 18:22
Show Gist options
  • Save ck1125/1056841 to your computer and use it in GitHub Desktop.
Save ck1125/1056841 to your computer and use it in GitHub Desktop.
Abridged Link Text Node lookup StepDefinition
import cuke4duke.annotation.I18n.EN.Then;
import helpers.SeleniumWrapper;
import helpers.WebPageHelpers;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import static helpers.SeleniumFactory.getSelenium;
import static org.junit.Assert.*;
public class linknodelookup {
private static final String JS_FIND_FIRST_TEXT_NODE_VALUE = "return arguments[0].firstChild.nodeValue";
@Then("^my link must have the following text (.*)$")
public void linkMustHaveTextNodeWithSuppliedLabel(String label) {
JavascriptExecutor executor = (JavascriptExecutor)getSelenium();
String linkXpath = "//div[@class='arbitrary-div']/ul/li[2]/a";
WebElement element = driver.findElement(By.xpath(linkXpath);
String text = (String)executor.executeScript(JS_FIND_FIRST_TEXT_NODE_VALUE, element);
assertTrue(String.format("%s should be present in link",label), text.equals(label));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment