Finders
Finders in WebTau is the initial web element selection that could select one or more elements.
Finders in WebTau is the initial web element selection that could select one or more elements.
Use $ or browser.element to select an element by a given css selector ( https://www.w3schools.com/cssref/css_selectors.asp Read W3Schools CSS selectors to learn all kind of CSS selection techniques). def welcomeMessage = $("#welcome") welcomeMessage.should == "hello" If more than one element is matched, the first one will be used for actions and assertions. def menu = $("ul li a") menu.should == "book" While click and sendKeys will always work on a first element only, the matchers can work with a list of things. def menu = $("ul li a") menu.should == ["book", "orders", "help"] Note: declaring element this way will not trigger element search right away.
You can use filters to narrow down elements selected by finders.Use get method to filter found elements byElement number Element text Element regexp def ordersMenu = $("ul li a").get(2) ordersMenu.should == "orders" def ordersMenu = $("ul li a").get("orders") ordersMenu.should == "orders" def ordersMenu = $("ul li a").get(~/ord/) ordersMenu.should == "orders"
def button = $("button") def helloMessage = $("#hello-message") button.nearby(helloMessage).should == "World2"
After you filtered, you can use finders again to find nested elements. def ordersMenu = $("ul li").get(2).find("a") ordersMenu.should == "orders"
def welcomeMessage = $("#welcome") def wrapper = welcomeMessage.parent() wrapper.attribute("class").should == "wrapper-class"
def welcomeMessage = $("#welcome") def mainWrapper = welcomeMessage.parent(".top-section") mainWrapper.attribute("class").should == "top-section"