这个简单的Java/Selenium WebDriver代码如何工作 [英] How does this simple Java/Selenium WebDriver Code work

查看:137
本文介绍了这个简单的Java/Selenium WebDriver代码如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是硒的新手,昨天从看几段视频开始学习硒.我对这段代码的工作方式有疑问.请解释.

I am new to selenium and started learning it yesterday by watching few videos. I have a doubt regarding how this piece of code works. Please explain.

// I am creating a Object reference for the FirefoxDriver class
FirefoxDriver f=new FirefoxDriver();

//findElementByClassName method is available in FirefoxDriver class. i Can understand this.
f.findElementByClassName("Email").sendKeys("abc");

sendkeys("abc")如何工作?它也是FirefoxDriver类的方法吗?但是,我知道它在测试字段中输入"abc".我只是想知道如何在这里使用它.

How does sendkeys("abc") work? Is it also a method of FirefoxDriver class? I however know that it enters "abc" in the test field. I just wanted to know how it can be used here.

我以不同的方式尝试了相同的代码.在这里,如何将WebElement类与firefoxDriver类一起使用?

I have tried the same piece of code in a different way. Here, how can the WebElement Class being used along with firefoxDriver class?

FirefoxDriver f=new FirefoxDriver();
WebElement ex= f.findElementByClassName("Email");
ex.sendKeys("abc");

这两个代码都能正确执行所需的代码,但是它们如何工作?

Both these pieces of codes do the required work correctly, but how do they work?

推荐答案

是的,这两段代码都能正常工作.

Yes, both of those pieces of code work.

基本上,当您执行任何findElement函数时,它将返回一个WebElement. WebElement是指向附加到浏览器的HTML元素的对象.然后,当您sendKeys()时,驱动程序将转到该元素并键入.

Basically, when you do any findElement function, it will return a WebElement. A WebElement is an object that points to an HTML element attached to the browser. Then when you sendKeys(), the driver will then go to that element and type.

这篇关于这个简单的Java/Selenium WebDriver代码如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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