【问题标题】:Cant click on a specific button in selenium webdriver [duplicate]无法单击 selenium webdriver 中的特定按钮 [重复]
【发布时间】:2021-01-09 13:01:27
【问题描述】:

我无法将商品添加到购物车,因为未选择按钮。

the button in question is the "ADD TO CART" and its only classification is its class called "btn_primary btn_inventory".

this button should add the item selected to the cart as shown:

这是我用来让它选择一个随机按钮并单击它的非工作代码:

WebElement areaInventory = navegador.findElement(By.id("inventory_container"));
        List<WebElement> l1 = areaInventory.findElements(By.className("btn_primary btn_inventory"));
        for(int i=0;i< l1.size();i++){
            Random r = new Random();
            l1.get(r.nextInt(6)).click();
        }

【问题讨论】:

    标签: selenium-webdriver


    【解决方案1】:

    尝试进行下面提到的更改。

    更改List&lt;WebElement&gt; l1 = areaInventory.findElements(By.className("btn_primary btn_inventory"));

    List&lt;WebElement&gt; l1 = areaInventory.findElements(By.cssSelector(".btn_primary.btn_inventory"));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-02
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 2014-01-04
      • 1970-01-01
      • 2019-02-04
      • 2017-01-17
      相关资源
      最近更新 更多