简体   繁体   English

为什么我不能单击但可以右键单击Selenium

[英]Why I can't click but can right click with Selenium

enter image description here I specified the button class in CSS selector and right click executed. 在这里输入图像描述,我在CSS选择器中指定了按钮类,然后右键单击了。 Then options displayed on the button, so it assure that the correct element position has been acquired. 然后,选项显示在按钮上,以确保已获取正确的元素位置。

javascript javascript

        .then(function () {
            var element = driver.findElement(By.className('xxx'))
            return element;
        })
        .then(function (element) {
            var action = new webdriver.ActionSequence(driver)
            action.click(element, webdriver.Button.RIGHT).perform()
        })

Problem arises when just click is executed, instead of right click. 仅执行单击而不是单击鼠标右键时会出现问题。

        .then(function (element) {
            var action = new webdriver.ActionSequence(driver)
            action.click(element).perform()
        })

I hope the event when the button is pressed to be executed, but it doesn't. 我希望在按下按钮时执行该事件,但事实并非如此。 I cannot find any error message. 我找不到任何错误消息。 I really don't know why... 我真的不知道为什么

html html

  <button class="btn btn-default btn-play">
    <span class="glyphicon glyphicon-play" aria-hidden="true">
    </span>
      " play "
  </button>

I tried to select each class and result was same. 我试图选择每个班级,结果都是一样的。

button before button after 按钮之前 按钮之后

Since the aria-hidden="true" you can achieve this by directly clicking using javascript. 由于aria-hidden="true"您可以通过直接使用javascript单击来实现此目的。 :) :)

driver.executeScript("document.getElementsByClassName('btn btn-default btn-play')[0].click()")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM