I have page where list of products are displayed, I need to click only particular type of listings from the list so saved this particular type as "Webelement". Now, whenever I land on this page, I check a condition and click only on first product. But, my requirement is after checking a condition, I need to click any random product in the list. see my code below. kindly suggest.
driver.findElement(By.linkText("ALL EQUIPMENT")).click(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); List <WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']")); for (int i=0; i < listings.size(); i++) { WebElement requiredlisting = listings.get(i); System.out.println(i); requiredlisting.click(); Thread.sleep(10000); getvalue = driver.findElement(By.xpath("//div[7]/span")).getText(); System.out.println(getvalue); driver.findElement(By.xpath("//div[3]/div[2]/input")).click(); Thread.sleep(10000); driver.findElement(By.id("listingQuestion")).click(); Thread.sleep(10000); driver.findElement(By.id("listingQuestion")).sendKeys("Where is the listing located"); Thread.sleep(10000); driver.findElement(By.name("submitq")).click(); Thread.sleep(10000); driver.findElement(By.xpath("//div/div[2]/div[3]/input")).click(); Thread.sleep(10000); driver.findElement(By.id("uname")).click(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.findElement(By.linkText("Sign Out")).click();