【问题标题】:Performing a Click on div Elements执行单击div元素
【发布时间】:2019-03-23 12:09:07
【问题描述】:

我正在尝试使用量角器单击 div 元素,但它给了我一个错误,提示“元素不可交互”。这是一个菜单,当您单击其中一个 div 时,应该会弹出另一个菜单。

    <div class="col">

        <div class="games">

                <div class="game" rel="board">
                    Chess
                </div>

                <div class="game" rel="sports">
                    Basketball
                </div>

                <div class="game" rel="active">
                    Exercise
                </div>

        </div>

    </div>

我尝试的是

    element.all(by.cssContainingText('.game','Exercise')).click();
    element(by.cssContainingText('.game','Chess')).click();

【问题讨论】:

    标签: javascript html selenium selenium-webdriver protractor


    【解决方案1】:
    element.all(by.cssContainingText('.game','Exercise')).click();
    browser.wait(ExpectedCondition.elementToBeClickable(element(by.cssContainingText('.game','Chess')),60000,'Wait for the element to become clickable'));
    element(by.cssContainingText('.game','Chess')).click();
    

    如果这没有帮助,请尝试在尝试访问元素之前添加 browser.sleep()

    【讨论】:

      【解决方案2】:

      JS 点击

      export async function jsClickButton(button: ElementFinder) {
      
          try {
              return await browser.executeScript('arguments[0].click()', button).then(async() => {
                  console.log('Element has been clicked.');
              });
          } catch (error) {
              console.log('Element could not be clicked', error);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-10
        • 2020-07-31
        • 2016-09-05
        • 2013-04-08
        • 1970-01-01
        相关资源
        最近更新 更多