如何找到“游标"Selenium Webdriver在网页中的位置? [英] How to find "Cursor" position in webpage with Selenium Webdriver?

查看:67
本文介绍了如何找到“游标"Selenium Webdriver在网页中的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Java Script学习Selenium Webdriver,我问的这个问题可能对我来说很愚蠢.但是仍然想知道是否有可能.

I just started learning Selenium Webdriver using java Script, the question what I have asked might me a silly one. But still wanted to know whether it is possible or not.

根据我的问题,请仔细阅读以下示例

As per my question, please go through the below example

在任何登录页面中,输入有效的用户名",然后单击登录"按钮,它会显示一条错误消息请输入密码",并且光标"将位于密码"字段中

In any Login page, enter valid "Username" and click on "signin" button, it throws an error message "Please enter password" and the "cursor" will be located in "Password" field

因此,我们可以通过代码获取错误消息.现在,我们如何通过代码定位或标识网页中的光标"位置?

So, we can get the error message via code. Now, how can we locate or identify the "Cursor" position in the webpage via code?

推荐答案

根据定义,任何具有焦点的小部件也都具有光标.因此,driver.switchTo().activeElement()将返回当前聚焦的WebElement.它实际上并没有改变任何东西,只是返回了活动元素.您可以致电

By definition, any widget that has focus also has the cursor. So driver.switchTo().activeElement() will return the currently focused WebElement. It doesn't actually change anything, just returns the active element. You can call

expectedElement.equals(driver.switchTo().activeElement());

验证ExpectedElement是否具有焦点.

to verify that expectedElement has focus.

这篇关于如何找到“游标"Selenium Webdriver在网页中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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