Hey @Sradha,
As you have created an array of keywords and you want to search it in a random way. You can use normal script for searching in google and induce your array and pass your elements in a random manner using .random function. Again you can create an array of index of those key words. That's all.
Here is a code for doing that:-
import java.util.Random;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SerachRandom
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\Nabarupa\\chromedriver.exe");
String str[] = {"Hello World",
"India","Earth","Asia","Community","Selenium"}
try{
WebDriver driver=new ChromeDriver();
driver.get("https://www.google.com");
int j[] = {0,1,2,3,4,5};
Random generator = new Random();
int randomIndex = generator.nextInt(j.length);
int k = j[randomIndex];
driver.findElement(By.name("q")).sendKeys(str[k],Keys.ENTER);
Thread.sleep(5000);
driver.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Hope this helps.