[英]Selenium Webdriver using java
Why is the New keyword not needed when instantiating the WebElement class but not for the Select class in Selenium ? 为什么在实例化WebElement类时不需要New关键字,而在Selenium中选择Select类却不需要呢? For WebElement: 对于WebElement:
WebElement username = driver.findElement(By.id(“Email”));
But for Select: 但对于Select:
Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));
why the New keyword in Select and vice versa? 为什么在Select中使用New关键字,反之亦然?
Because WebElement
IS NOT a class it's an Interface reside in org.openqa.selenium
which extends SearchContext
and Select
is Class 因为WebElement
不是类,所以它是一个接口,驻留在org.openqa.selenium
,该接口扩展了SearchContext
并且Select
为Class
More info: You do not instantiate an Interface, just implementing them will have result. 更多信息:您无需实例化接口,只需实现它们就会有结果。 this will help you to understand 这将帮助您了解
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.