0

I'm wondering if it's possible to pass locator as parameter in data driven test? For example:

    //this is non-parameterized object RADIO_BUTTON locator

    WebElement radiobElm = driver.findElement(RADIO_BUTTON);
    radiobElm.click();

    vs. 

    //I'd like to pass locator "RADIO_BUTTON" as string (strRadioButton) from Excel sheet, so for each test iteration my script will click on different radio-buttons. Is it possible? 

    WebElement radiobElm = driver.findElement(strRadioButton);
    radioElm.click();
Russ
  • 15
  • 2
  • 5

2 Answers2

0

One of the many ways to accomplish this would be to use same method to find elements and read the locator from excel file.

 WebElement radiobElm = driver.findElement(By.xpath("Your xpath string from exel"));

Of course you have to do all of other works to read the correct cell from excel.

Saifur
  • 16,081
  • 6
  • 49
  • 73
  • I am glad that it worked! Please accept this as an answer and THAT is the way to thanks the people answer your question in stackoverflow – Saifur Nov 15 '14 at 00:59
0

Yes you can. You just have to get the data from the excel (using jexcelapi's getContents() method, for instance). Then, you can manipulate them accordingly as they come.

1- If it's an xpath, use this:

WebElement radiobElm = driver.findElement(By.xpath("Cell contents containing xpath of the webelement"));
radioElm.click();

2- If it's an id, use this:

WebElement radiobElm = driver.findElement(By.id("Cell contents containing id of the webelement"));
radioElm.click();

3- If it's an cssSelector, use this:

WebElement radiobElm = driver.findElement(By.cssSelector("Cell contents containing cssSelector of the webelement"));
radioElm.click();

Similar thing, can be applied for "className, name, linkText, partialLinkText, and tagName" also.

Subh
  • 4,354
  • 1
  • 13
  • 32