Hey @Jino, it was pretty good brain storming thing to do, eventually got a solution. Please let me know as whether it worked for you or not?
driver.findElement(By.className("LM6RPg")).sendKeys("comb");
driver.findElement(By.className("col-1-12")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//*[@id='container']/div/div[1]/div[2]/div/div[1]/div[2]/div[2]/div/div[1]")).click();
ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs2.get(0));
driver.close();
driver.switchTo().window(tabs2.get(1));
Thread.sleep(6000);
try
{
driver.navigate();
driver.findElement(By.xpath("//*[@id='container']/div/div[1]/div[2]/div/div[1]/div[1]/div[2]/div/ul/li[1]/button")).click();
}
catch (Exception e)
{
System.out.println(e);
}
driver.close();
I added a comb in my cart. I assume that you have already logged in.
You can view the way to login here:
https://www.edureka.co/community/33814/how-can-i-login-to-flipkart-using-selenium