RE: How to pass array of WebElement type to a method


Hi there,

I am trying to create 2 methods viz One method to locate web element on the page using driver.findElement. Method accepts set of multiple xpaths from excel file like xpath1,xpath2,xpath3… on. On next I have separated all xpaths based on ‘,’ comma sign using split() and saved them into an array ‘strarray’ and did driver.findElement(By.xpath(“strarray[i]”) using loop.

Now issue is that, I need to save these values into an array of WebElement type. After doing this, I need to return this array to some other method so that I can do further action using those returned value.

Is there any for implementing same. Or if I am wrong then please suggest a way.

Add Comment
7 Answers

I shall give you a sample program. You would learn more on tweaking this code.

import java.util.*;

class Listuser {
void a() {
String b[]={“1″,”2″};

void c(String b[]) {
int e=b.length;
for(int f=0;f<e;f++) {
System.out.print(b[f]+” “);//Single Space

public static void main(String args[]) {
Listuser ob=new Listuser();

// private void c(String[] b) {
// throw new UnsupportedOperationException(“Not yet implemented”);
// }

Doctor Answered on September 9, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.