简体   繁体   English

Java Selenium WebDriver-如何在不使用远程WebDriver的情况下设置ScrollBehavior(elementScrollBehavior)?

[英]Java Selenium WebDriver - How to set ScrollBehavior (elementScrollBehavior) without using Remote WebDriver?

on my website I'm trying to automate, there is a floating header. 在我要自动化的网站上,有一个浮动标题。 As selenium is always scrolling to the top of an element, I'm getting the error message that some other element would receive the click. 由于硒总是滚动到某个元素的顶部,因此我收到一条错误消息,提示其他元素将获得点击。 After searching a bit on the net, there should be a solution to set the scroll behavior (elementScrollBehavior) as a desired capability. 在网上搜索了一点之后,应该有一个解决方案,将滚动行为(elementScrollBehavior)设置为所需的功能。

Now my question: As Desired Capabilities is for remote WebDriver implementation, it's not really useful in my case. 现在我的问题是:由于所需功能是用于远程WebDriver实施的,因此对于我而言,它并不是真正有用的。 Is there a possibility to change the scroll behavior in a way, that I can run my local instance with the behavior of scolling to buttom of an element? 是否有可能以某种方式更改滚动行为,使我可以以局部化的方式运行本地实例?

Many Thanks & Regards! 非常感谢和问候!

Desired capabilities are not only for RemoteWebDriver implementation, you can set it even on your local driver instances. 所需功能不仅适用于RemoteWebDriver实施,甚至可以在本地驱动程序实例上进行设置。 For example, if you are using FirefoxDriver you could do something like this in your case: 例如,如果您使用的是FirefoxDriver ,则可以根据需要执行以下操作:

DesiredCapabilities cap = new DesiredCapabilities();
driver = new FirefoxDriver(cap.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, 1);

You can also use RemoteWebDriver on your local machine (just pass localhost url), your localhost can also be selenium node, it doesn't have to be on some remote machine. 您还可以在本地计算机上使用RemoteWebDriver (只需传递localhost URL),您的localhost也可以是selenium节点,它不必在某些远程计算机上。

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

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