如何向下滚动Selenium(C#)中的子部分?(How to scroll down a sub

编程入门 行业动态 更新时间:2024-10-17 13:31:06
如何向下滚动Selenium(C#)中的子部分?(How to scroll down a sub-section in Selenium (C#)?)

我使用C#中的Selenium Webdriver在UI上测试网格,网格上有网格。

网格有自己的滚动条,我想向下滚动到网格的底部,以检查当我通过模态窗体添加它时出现的某个结果(UI测试当前失败,因为它无法看到结果直到我向下滚动)。

如何定位网格上的滚动条而不是主网页上的普通滚动条? 这是我的网格滚动条的HTML:

<div class="ScrollbarLayout_face ScrollbarLayout_faceVertical public_Scrollbar_face" style="height: 367.38px; transform: translate3d(0px, 148.535px, 0px); backface-visibility: hidden;"></div>

我正在考虑使用下面的代码,但我想不出如何将网格底部的元素定位到滚动到?

WebElement element = driver.findElement(By.id("my-id")); Actions actions = new Actions(driver); actions.moveToElement(element); actions.perform();

I am UI-testing a web page with a grid on it, using Selenium Webdriver in C#.

The grid has its own scroll bar and I would like to scroll down to the bottom of the grid to check a certain result has appeared when I add it through a modal form (the UI test is currently failing as it can't see the result until I scroll down).

How do I target the scroll bar on the grid as opposed to the normal scroll bar on the main webpage? This is the HTML of my grid's scroll bar:

<div class="ScrollbarLayout_face ScrollbarLayout_faceVertical public_Scrollbar_face" style="height: 367.38px; transform: translate3d(0px, 148.535px, 0px); backface-visibility: hidden;"></div>

I was thinking of using the below code, but I can't think how to target an element at the bottom of the grid to scroll to?

WebElement element = driver.findElement(By.id("my-id")); Actions actions = new Actions(driver); actions.moveToElement(element); actions.perform();

最满意答案

首先使用任何事件将焦点设置为任何网格对象

driver.FindElement(By.XPath("/html/body/div[2]//table/tbody/tr[1]/td[1]")).Click();

然后添加以下两行:

Actions actions = new Actions(driver); actions.SendKeys(OpenQA.Selenium.Keys.End).Build().Perform();

First set focus to any object of grid by using any event

driver.FindElement(By.XPath("/html/body/div[2]//table/tbody/tr[1]/td[1]")).Click();

Then add below two lines:

Actions actions = new Actions(driver); actions.SendKeys(OpenQA.Selenium.Keys.End).Build().Perform();

更多推荐

本文发布于:2023-07-26 00:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268397.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Selenium   scroll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!