0

step to reach that page. url:http://automationpractice.com/

  1. search product.
  2. hover a product and click Quick view
  3. Click Add to cart
  4. Try to interact to any element from light box. // there is no iframe.

Lightbox image

html code.

enizium
  • 1
  • 1
  • 1
    as I see it is another iframe, try to switch between frames, here is how you can do it: https://stackoverflow.com/questions/10879206/how-to-switch-between-frames-in-selenium-webdriver-using-java – cheparsky Jul 26 '22 at 18:08
  • @cheparsky, I don't see any iframe. – enizium Jul 29 '22 at 01:37

1 Answers1

0

Using Selenide this, a little ugly, code working for me:

    @Test
    public void addItemToCart() {
        open("http://automationpractice.com/");
        $(By.xpath("//*[@id=\"homefeatured\"]/li[1]/div/div[1]/div")).hover();
        $(By.xpath("//*[@id=\"homefeatured\"]/li[1]/div/div[1]/div/a[2]/span")).click();
        switchTo().frame($x("//*[@id=\"index\"]/div[2]/div/div/div/div/iframe"));
        $x("//*[@id=\"add_to_cart\"]/button").shouldBe(visible, Duration.ofSeconds(10));
        $x("//*[@id=\"add_to_cart\"]/button").click();
        $x("//*[@id=\"layer_cart_product_price\"]").shouldBe(visible, Duration.ofSeconds(10));
        assert $x("//*[@id=\"layer_cart_product_price\"]").text().equals("$16.51");
        $x("//*[@id=\"layer_cart\"]/div[1]/div[2]/div[4]/a/span").click();
        assert $("#cart_title").text().equals("Shopping-cart summary");
    }

As I said a problem was in iframe.

cheparsky
  • 514
  • 6
  • 20