Search code examples
javaseleniumselenium-webdriverbddqaf

Get webelement text in QAF


I would like to get the text of a particular webelement in a web page in QAF. With selenium we use

element(by.id('id')).getAttribute('value');

How do I write the above code in QAF ?


Solution

  • You can use the same way as you are using in normal selenium for example:

    driver.findElement(By.id("id")).getAttribute('value');
    

    In addition to that, with qaf there are multiple ways to achieve it. Let say your locator is id=id, To create element object you can use one of the following way:

    new QAFExtendedWebElement(loc)
    //or
    driver.findElement(loc)
    

    short hand:

    import static com.qmetry.qaf.automation.ui.webdriver.ElementFactory.$;
    
    
    $(loc)
    

    To get value in code

       String val = $(loc).getAttribute("value");
    

    To assert/verify/wait value in code

        $(loc).verifyValue(expectedValue);
        $(loc).assertValue(expectedValue);
        $(loc).waitForValue(expectedValue);
    

    Using inbuilt steps from qaf-support:

        import static com.qmetry.qaf.automation.step.CommonStep.*;
    
        verifyValue(loc, value);
        assertValue(loc, value);
        waitForValue(loc, value);
    

    Steps to assert/verify/wait value in BDD

        verify 'loc' value is 'expectedValue'
        assert 'loc' value is 'expectedValue'
        wait until 'loc' value is 'expectedValue'