I'm trying to use isSelected()
method on Amazon website.
I'm trying to tick the check-box of item filter and then read the status of check-box by isSelected()
but it always returns false message.
Please help me to overcome this problem.
package seleniumProgram;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.xml.LaunchSuite;
public class Check_isDisplayed_Enabled_Selected extends A_openBrowser {
public static void main(String[] args) throws InterruptedException {
openChrome("www.amazon.com");
WebElement search = driver.findElement(By.xpath("//input[@id='twotabsearchtextbox']"));
System.out.println("Search box is Displayed = "+search.isDisplayed());
System.out.println("Search box is Enabled = "+search.isEnabled());
driver.navigate().to("https://www.amazon.com/s?k=Nintendo+Switch+Games&i=videogames&bbn=16227133011&rh=n%3A16227133011&dc&ds=v1%3Au77TZDZ%2FgBsOBF9WBVz5WxCcRXqJa6CeSHU8sDYD8Dk&pf_rd_i=23508887011&pf_rd_m=ATVPDKIKX0DER&pf_rd_p=434db2ed-6d53-4c59-b173-e8cd550a2e4f&pf_rd_r=CVZSGC265EZ08YTW0ZDE&pf_rd_s=merchandised-search-5&pf_rd_t=101&qid=1653816583&rnid=2528832011&ref=sr_nr_p_89_1");
WebElement box = driver.findElement(By.xpath("//li[@id='p_89/U&I Entertainment']"));
System.out.println("U&I Entertainment CheckBox is Selected = "+box.isSelected());
//driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.findElement(By.xpath("//li[@id='p_89/U&I Entertainment']")).click();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
WebElement clik = driver.findElement(By.xpath("//body[1]/div[1]/div[2]/div[1]/div[2]/div[1]/div[3]/span[1]/div[1]/div[1]/div[1]/div[3]/ul[1]/li[2]/span[1]/a[1]/div[1]/label[1]/i[1]"));
System.out.println("U&I Entertainment CheckBox is Selected = "+clik.isSelected());
driver.close();