Selenium Java 中 By 关键字的用途是什么

发布于 2025-01-17 06:54:13 字数 543 浏览 1 评论 0原文

示例代码:

public class RediffLoginPage

{
    Webdriver driver;
    public RediffLoginPage(Webdriver driver){
        this.driver=driver;
    }

    By username=By.xpath(".//*(@id='login1']");
    By Password=By.name("passwd");
}

public Webelement Emailid()
{
    return driver.findElement(username);
}

public Webelement Password(){return driver.findElement(Password);}

在这一行中,

By username=By.xpath(".//*(@id='login1']");

第一个 By 关键字的用途是什么?

它是测试用例的对象存储库代码。

Sample Code:

public class RediffLoginPage

{
    Webdriver driver;
    public RediffLoginPage(Webdriver driver){
        this.driver=driver;
    }

    By username=By.xpath(".//*(@id='login1']");
    By Password=By.name("passwd");
}

public Webelement Emailid()
{
    return driver.findElement(username);
}

public Webelement Password(){return driver.findElement(Password);}

In this line,

By username=By.xpath(".//*(@id='login1']");

what's the purpose of first By keyword here?

It's object repository code for a testcase.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青春如此纠结 2025-01-24 06:54:13

扩展 < em>java.lang.Object 并定义为:

public abstract class By
extends java.lang.Object

Mechanism used to locate elements within a document. In order to create your own locating mechanisms, it is possible to subclass this class and override the protected methods as required, though it is expected that all subclasses rely on the basic finding mechanisms provided through static methods of this class:

 public WebElement findElement(WebDriver driver) {
     WebElement element = driver.findElement(By.id(getSelector()));
     if (element == null)
       element = driver.findElement(By.name(getSelector());
     return element;
 }
 

By 具有以下直接已知子类:

Class By

Class By extends java.lang.Object and is defined as:

public abstract class By
extends java.lang.Object

Mechanism used to locate elements within a document. In order to create your own locating mechanisms, it is possible to subclass this class and override the protected methods as required, though it is expected that all subclasses rely on the basic finding mechanisms provided through static methods of this class:

 public WebElement findElement(WebDriver driver) {
     WebElement element = driver.findElement(By.id(getSelector()));
     if (element == null)
       element = driver.findElement(By.name(getSelector());
     return element;
 }
 

By have the following direct known Subclasses:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文