I want to select all the products having rating 4.5, I could do that with the help received from StackExchange. Now I want to add the products with rating 4.5 to the cart. However, I am not able to customize the XPath. I tried the below XPath:
//*[@class='btn__inner']
Code:
package Test_package;
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class rating {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver","C:\\Chrome\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.coopathome.ch/de");
driver.findElement(By.xpath(".//*[@id='mastheadMyAccountLink']/span")).click();
Thread.sleep(2000);
driver.findElement(By.id("j_username")).sendKeys("[email protected]");
driver.findElement(By.id("j_password")).sendKeys("Soniya@123");
driver.findElement(By.id("loginOverlaySubmitLoginFormButton")).click();
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[@id='nav']/ul/li[1]/a/span")).click();
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[@id='subnav--item-m_0001']/li[1]/ul[1]/li[1]/a")).click();
//String a=driver.findElement(By.xpath("//div[@class='product-item__rating']/span")).getText();
//System.out.println(a);
List<WebElement> b=driver.findElements(By.xpath("//div[@class='product-item__rating']/span[contains(.,'4.5')]"));
System.out.println(b.size());
for(WebElement a:b)
{
System.out.println(a.getText());
}
}