Selenium命令在Chrome Web驱动程序中不起作用(与Firefox一起使用) [英] Selenium commands not working in Chrome web driver (working with firefox)

查看:154
本文介绍了Selenium命令在Chrome Web驱动程序中不起作用(与Firefox一起使用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写集成/e2e测试,由于某种原因,任何硒驱动程序命令都无法与chromedriver一起使用,但是它们可以与firefox驱动程序和firefox无头驱动程序完美地协同工作.

I'm writing integration/e2e tests and for some reason any selenium driver commands don't see to be working with chromedriver, but they are working flawlessly with firefox driver and the firefox headless driver.

尝试的命令: moveByOffset doubleClick

尝试了两种Geb的交互方法

Tried both Geb's Interact method

interact {
 doubleClick(centerClickable)
}

并直接访问网络驱动程序:

and accessing the webdriver directly:

def driver = browser.getDriver()
Actions action = new Actions(driver)
WebElement element= driver.findElement(By.className("vis-drag-center"))
def doubleclick = action.doubleClick(element).build()
doubleclick.perform()

这两种方法都可以与firefox驱动程序一起使用.两者都无法与chrome驱动程序一起使用.

Both methods work with the firefox driver. Neither work with chrome driver.

GebConfig.groovy文件的设置如下:

GebConfig.groovy file is set up as thus:

import io.github.bonigarcia.wdm.WebDriverManager
import org.openqa.selenium.Dimension
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions

def chromeWebDriverVersion = '70.0.3538.67'

def driverFirefox = {
  WebDriverManager.firefoxdriver().setup()
  def driver = new FirefoxDriver()
  driver.manage().window().setSize(new Dimension(width, height))
  return driver
}

// ChromeDriver reference: https://sites.google.com/a/chromium.org/chromedriver/
// Download and configure ChromeDriver using https://github.com/bonigarcia/webdrivermanager
def driverChrome = {
  WebDriverManager.chromedriver().version(chromeWebDriverVersion).setup()
  def driver = new ChromeDriver()
  driver.manage().window().setSize(new Dimension(width, height))
  return driver
}

environments {
  firefox {
    driver = driverFirefox
  }
  chrome {
    driver = driverChrome
  }
//driver = driverFirefox
driver = driverChrome

我也尝试了chrome版本2.43.

I also tried version 2.43 of chrome.

其他信息:

  • Mac Mojave
  • 硒v 3.7.0
  • geb v 2.2
  • spockcore v 1.1-groovy-2.4
  • groovy v 2.4.5
  • webdrivermanager v 3.0.0

如果有人感兴趣,则测试正在做什么:单击以选择vis.js元素.睡眠一秒钟(此处未包含代码),然后双击以打开/激活它.或拖动它.

If anyone is interested, what the test is doing: Selecting a vis.js element by clicking on it. Sleeping for a second (code not included here), then opening/activating it by double clicking it. Or dragging it.

除了硒作用之外,chromedriver和geb都可以正常工作.只是现在,我需要doubleClick和moveByOffset(而不是移动到元素!)才出现问题,无法正常工作

Apart from the selenium actions everything works fine with chromedriver and geb. It's only now that I need the doubleClick and moveByOffset (not move to an element!) that I'm getting issues getting things to work properly

我在这里发现了类似的问题,可能是相同的问题.也许不吧.但是没有提供解决方案: Chrome中的硒Web驱动程序DragAndDropToOffset无法正常工作吗?

I found a similar question on here, might be the same issue. Maybe not. But there's no solution provided: Selenium Web Driver DragAndDropToOffset in Chrome not working?

我们非常感谢您的帮助.

Any help is hugely appreciated.

推荐答案

感谢您的回复. 您的测试也对我有用.这使我认为,硒的chromedriver和firefox驱动程序如何实现doubleclick和dragAndDropBy操作以及我们的应用程序对命令的响应方式之间的差异之间仅存在一些底层交互.

Thank you for your response kriegaex. Your tests work for me as well. This leads me to think there's just some lower-level interaction between differences in how selenium's chromedriver and firefox driver have implemented the doubleclick and dragAndDropBy actions + the way our application responds to commands.

对于其他观察到类似行为的人,我使用一种变通办法,在其中我为chromedriver添加了其他操作.也许最好是找出您应该使用并触发的KEYDOWN事件等,或者找出为什么应用程序不响应这些事件的方法.但是我觉得已经花了很多时间:)

For any other people observing similar behaviour, I use a work-around where I add an additional action for chromedriver. Perhaps it's nicer to actually find out which KEYDOWN events etc. you should be using and fire those, or perhaps find out why application isn't responding to these events. But I feel like enough time is spent on this already :)

  if (browser.getDriver().toString().contains("chrome")) {
//      Work-around for chromedriver's double-click implementation
    content.click()
  }

  interact {
    doubleClick(content)
  }

对于dragAndDropBy:

And for the dragAndDropBy:

  def drag(Navigator content, int xOff, int yOff) {
    //Work-around: move additional time for when chrome driver is used.
    int timesToMove = browser.getDriver().toString().contains("chrome") ? 2 : 1

    interact {
      clickAndHold(content)
      timesToMove.times {
        moveByOffset(xOff, yOff)
      }
      release()
    }
  }

这篇关于Selenium命令在Chrome Web驱动程序中不起作用(与Firefox一起使用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆