Skip to content
sharonlambson edited this page Sep 15, 2017 · 42 revisions

Examples

Locate list of PageElements

    // defining Page Elements
PageElement inputElement = new PageElement("Input Elements", FindBy.tagName("input"));
    // getting a list of Page Elements
List<PageElement> inputElementList = browserWrapper.getPageElements(inputElement);

Locate single PageElement

    // defining Page Elements
PageElement inputQueryBox = new PageElement("Google Query Box", FindBy.name("q"));
PageElement buttonGoogleSearch = new PageElement("Google Search Button", FindBy.value("Google Search"));
    // interacting with Page Elements
browserWrapper.type(inputQueryBox, "searching for stuff");
browserWrapper.click(buttonGoogleSearch);

Locate a PageElement within another PageElement

PageElement filesTable = new PageElement("Files table", FindBy.className("files"));
PageElement inputElements = new PageElement("Examples Link", In.ParentElement(filesTable), FindBy.hrefContains("example"));

Locate a PageElement within another PageElement without defining the Parent PageElement explicitly

PageElement inputElements = new PageElement("Examples Link", In.ParentElement(FindBy.className("files")), FindBy.hrefContains("example"));

Locate a PageElement within an iFrame that has and ID

PageElement informationLink = new PageElement("FrameID", In.Frame("myDemoFrameID"), FindBy.name("myElement"));

Locate a PageElement within an iFrame that does not have an ID

PageElement demoIframe = new PageElement("Demo iFrame", FindBy.name("myDemoFrame"));
PageElement forecastLink = new PageElement("Forecast Link", In.Frame(demoIframe), FindBy.attributeValue("data-qa", "forecast-link"));

Locate a PageElement by a specific attribute and value

PageElement imageAttributeValue = new PageElement("Image element by attribute value", FindBy.attributeValue("data-qa", "slick-logo"));

Locate a PageElement by the text contained in the element

PageElement labelByText = new PageElement("Element by text", FindBy.text("Some Text");

Locate a PageElement relative to a following sibling

Given this html snippet: <div> <input type="checkbox"> <label>Need to click</label> </div>

PageElement checkBox1 = new PageElement("Checkbox", Relative.FollowedBySibling(FindBy.text("Need to click"), "input");

Locate a PageElement relative to a preceding sibling

Given this html snippet: <div> <label>Need to click</label> <input type="checkbox"> </div>

PageElement checkBox1 = new PageElement("Checkbox", Relative.PrecededBySibling(FindBy.text("Need to click"), "input");

Locate a PageElement relative to a descendent

Given this html snippet: <a> <label>Need to click</label> </a>

PageElement link = new PageElement("Link", Relative.Descendent(FindBy.text("Need to click"), "a");

Clone this wiki locally