Multiple locator for webelement search with webdriver

I am using Selenium Webdriver with QAF . The problem I'm facing is related to finding an element on a web page. for several elements, different locators work at different times.

For example, sometimes name = nameA works, and sometimes name = nameB (maybe it depends on different AUT environments, I don't know).

Find the code below:

public class HomePage extends WebDriverBaseTestPage<WebDriverTestPage> {


    @FindBy(locator="name=nameA")
    private QAFWebElement btnSomeElement;


    @Override
    protected void openPage(PageLocator locator, Object... args) {
        driver.get("/");
    }
}

What should I do to solve this problem?

+4
source share
4 answers

QAF, , . , Locator, .

:

page.loc

my.ele.locator=<locatorStretegy>=<locator>
my.ele.locator=name=elemName

:

@FindBy(locator = "my.ele.loc")
private QAFWebElement btnSomeElement; Now coming to your problem, if most of the locator very with environment then you can utilize

QAF. , QAF. :

my.ele.locator=['css=.cls#eleid','name=eleName','name=eleName2']
my.ele.locator=['name=eleNameEnv1','name=eleNameEnv2']
+3

, , css xpath.

html- /, .

, , , , :

css: [name=nameA], [name=nameB]
xpath: //*[@name='nameA' or @name='nameB']

+1

. , . , xpath, .

@FindBy(locator = "xpath=//button[text()='ButtonName']")
private QAFWebElement btnSomeElement;
0
btn.login.page.logon.button = {\"locator\":[\"xpath=//div[contains(@id,'logonbutton')]//span[contains(text(),'Logon')]\",\"xpath=//*[contains(text(),'Logon') or @id='__screen0-logonBtn']\"]}

QAF. .

0

Source: https://habr.com/ru/post/1655633/


All Articles