【问题标题】:unable to interact with lightbox in selenium无法与 selenium 中的灯箱交互
【发布时间】:2022-08-11 00:16:55
【问题描述】:

到达该页面的步骤。网址:http://automationpractice.com/

  1. 搜索产品。
  2. 悬停产品并单击快速查看
  3. 点击加入购物车
  4. 尝试与灯箱中的任何元素进行交互。 // 没有 iframe。

    Lightbox image

    html code.

标签: java selenium selenium-webdriver


【解决方案1】:

使用 Selenide 这个有点难看的代码对我有用:

    @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");
    }

正如我所说,iframe 中存在问题。

【讨论】:

    猜你喜欢
    • 2022-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多