<small id='x7PLq'></small><noframes id='x7PLq'>

    <i id='x7PLq'><tr id='x7PLq'><dt id='x7PLq'><q id='x7PLq'><span id='x7PLq'><b id='x7PLq'><form id='x7PLq'><ins id='x7PLq'></ins><ul id='x7PLq'></ul><sub id='x7PLq'></sub></form><legend id='x7PLq'></legend><bdo id='x7PLq'><pre id='x7PLq'><center id='x7PLq'></center></pre></bdo></b><th id='x7PLq'></th></span></q></dt></tr></i><div id='x7PLq'><tfoot id='x7PLq'></tfoot><dl id='x7PLq'><fieldset id='x7PLq'></fieldset></dl></div>
      • <bdo id='x7PLq'></bdo><ul id='x7PLq'></ul>

    1. <legend id='x7PLq'><style id='x7PLq'><dir id='x7PLq'><q id='x7PLq'></q></dir></style></legend>
      <tfoot id='x7PLq'></tfoot>

    2. 如何使用 Selenium WebDriver 滚动到元素

      How to scroll to element with Selenium WebDriver(如何使用 Selenium WebDriver 滚动到元素)
      1. <i id='vM8Xi'><tr id='vM8Xi'><dt id='vM8Xi'><q id='vM8Xi'><span id='vM8Xi'><b id='vM8Xi'><form id='vM8Xi'><ins id='vM8Xi'></ins><ul id='vM8Xi'></ul><sub id='vM8Xi'></sub></form><legend id='vM8Xi'></legend><bdo id='vM8Xi'><pre id='vM8Xi'><center id='vM8Xi'></center></pre></bdo></b><th id='vM8Xi'></th></span></q></dt></tr></i><div id='vM8Xi'><tfoot id='vM8Xi'></tfoot><dl id='vM8Xi'><fieldset id='vM8Xi'></fieldset></dl></div>
            <bdo id='vM8Xi'></bdo><ul id='vM8Xi'></ul>
              <tbody id='vM8Xi'></tbody>
          • <tfoot id='vM8Xi'></tfoot>

            1. <legend id='vM8Xi'><style id='vM8Xi'><dir id='vM8Xi'><q id='vM8Xi'></q></dir></style></legend>
            2. <small id='vM8Xi'></small><noframes id='vM8Xi'>

                本文介绍了如何使用 Selenium WebDriver 滚动到元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如何让 Selenium WebDriver 滚动到特定元素以将其显示在屏幕上.我尝试了很多不同的选择,但都没有运气.这在 C# 绑定中不起作用吗?

                How do I get Selenium WebDriver to scroll to a particular element to get it on the screen. I have tried a lot of different options but have had no luck. Does this not work in the C# bindings?

                我可以让它跳转到一个特定的位置,例如

                I can make it jump to a particular location ex

                ((IJavaScriptExecutor)Driver).ExecuteScript("window.scrollTo(0, document.body.scrollHeight - 150)");
                

                但我希望能够将其发送到不同的元素,而无需每次都给出确切的位置.

                But I want to be able to send it to different elements without giving the exact location each time.

                public IWebElement Example { get { return Driver.FindElement(By.Id("123456")); } }
                

                例 1)

                ((IJavaScriptExecutor)Driver).ExecuteScript("arguments[0].scrollIntoView(true);", Example);
                

                例 2)

                ((IJavaScriptExecutor)Driver).ExecuteScript("window.scrollBy(Example.Location.X", "Example.Location.Y - 100)");
                

                我看的时候没有跳到页面下到元素,异常匹配元素正在离屏.

                When I watch it, it does not jump down the page to the element, and the exception matches the element being off screen.

                我在它之后添加了一个 bool ex = Example.Exists(); 并检查了结果.它确实存在(它是真的).它没有显示(因为它仍然在屏幕外,因为它没有移动到元素)它没有被选中??????

                I added an bool ex = Example.Exists(); after it and checked the results. It does Exist (its true). Its not Displayed (as its still offscreen as it has not moved to the element) Its not Selected ??????

                有人看到成功 By.ClassName.有谁知道在 C# 绑定中执行此 By.Id 是否有问题?

                Someone is seeing success By.ClassName. Does anyone know if there is a problem with doing this By.Id in the C# bindings?

                推荐答案

                这个问题有点老了,但我相信有比上面建议的更好的解决方案.

                Its little older question, but I believe that there is better solution than suggested above.

                这是原始答案:https://stackoverflow.com/a/26461431/1221512

                您应该使用 Actions 类来执行滚动到元素.

                You should use Actions class to perform scrolling to element.

                var element = driver.FindElement(By.id("element-id"));
                Actions actions = new Actions(driver);
                actions.MoveToElement(element);
                actions.Perform();
                

                这篇关于如何使用 Selenium WebDriver 滚动到元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                How to store delegates in a List(如何将代表存储在列表中)
                How delegates work (in the background)?(代表如何工作(在后台)?)
                C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                  • <small id='Yl80E'></small><noframes id='Yl80E'>

                  • <legend id='Yl80E'><style id='Yl80E'><dir id='Yl80E'><q id='Yl80E'></q></dir></style></legend>
                      <bdo id='Yl80E'></bdo><ul id='Yl80E'></ul>

                          <tbody id='Yl80E'></tbody>
                        <tfoot id='Yl80E'></tfoot>
                        1. <i id='Yl80E'><tr id='Yl80E'><dt id='Yl80E'><q id='Yl80E'><span id='Yl80E'><b id='Yl80E'><form id='Yl80E'><ins id='Yl80E'></ins><ul id='Yl80E'></ul><sub id='Yl80E'></sub></form><legend id='Yl80E'></legend><bdo id='Yl80E'><pre id='Yl80E'><center id='Yl80E'></center></pre></bdo></b><th id='Yl80E'></th></span></q></dt></tr></i><div id='Yl80E'><tfoot id='Yl80E'></tfoot><dl id='Yl80E'><fieldset id='Yl80E'></fieldset></dl></div>