Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98819

Selenium click on String array of elements

$
0
0

I have an String array that I get from a text file or CSV. I want Selenium to take that array and click on each checkbox element. The elements have this naming convention:

1.0.50.gecb16, 
1.1.50.gecb16, 
1.2.50.gecb16,
1.3.50.gecb16, ->to 50

I only want to click on the checkbox for each element to lets say 24

on this line:

driver.findElement(By.name(i)).click();

I am getting an error of: The method name(String) in the type By is not applicable for the arguments (String[])

Here is my Code:

@SuppressWarnings("resource")
    Scanner inFile1 = new Scanner(new File("4off.txt"));

    StringBuilder sb = new StringBuilder();
    while(inFile1.hasNext()) {
        sb.append(inFile1.nextLine());
    }

    String[] yourArray = sb.toString().split(", ");
    int i;

    System.out.println("This is the Array: " + "\n");
    Arrays.stream(yourArray).forEach(System.out::println);

    // launch Chrome and go to baseUrl
    driver.get(baseUrl);//baseUrl


   driver.findElement(By.name("pwd")).sendKeys(pass);

    Thread.sleep(1000);
    driver.findElement(By.name("login_button")).click();
    System.out.println("ATTEMPTING Login CLICK");
    driver.findElement(By.xpath("//*[@id=\'tabs\']/td[4]/a/img")).click();
    Thread.sleep(6000);
    System.out.println("ATTEMPTING Checkbox CLICK");


    ////This switches to the iframe called "mainContent"//// 
    driver.switchTo().frame("maincontent");

    ////For loop that will go through all of the elements in the array:
    for (i = 0; i <= 24; i++)
    {
        driver.findElement(By.name(i)).click();
    }

Viewing all articles
Browse latest Browse all 98819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>