Selenium webdriver @通过类Select查找错误
我试图在类Selenium webdriver @通过类Select查找错误,selenium-webdriver,pageobjects,Selenium Webdriver,Pageobjects,我试图在类Select中实现带有注释@FindBy的页面对象。在Eclipse中,它显示以下消息: type By中的方法id(字符串)不适用于参数(WebElement) 我不知道为什么会有这样的信息。按照下面的错误代码和图像进行操作 类FaturamentOgeratmentoosPage public class FaturamentoGeTratamentoOsPage { WebDriver driver; @FindBy(id = "cboMotivo")
Select
中实现带有注释@FindBy
的页面对象。在Eclipse中,它显示以下消息:
type By中的方法id(字符串)不适用于参数(WebElement)
我不知道为什么会有这样的信息。按照下面的错误代码和图像进行操作
类FaturamentOgeratmentoosPage
public class FaturamentoGeTratamentoOsPage {
WebDriver driver;
@FindBy(id = "cboMotivo")
WebElement CBOMotivo;
public FaturamentoGeTratamentoOsPage(WebDriver driver) {
this.driver = driver;
}
public void preencherCampoMotivo(String CampoMotivo) {
// Campo Motivo
WebElement campoMotivo = driver.findElement(By.id(CBOMotivo));
Select slcMotivo = new Select(campoMotivo);
slcMotivo.selectByVisibleText(CampoMotivo);
}
public void preencherCampoSubmotivo(String CampoSubMotivo) throws Exception {
}
}
等级FaturamentoeConnectivedFacilidTest
public class FaturamentoGeConectividadeFacilidadesTest {
static WebDriver driver;
@Before
public void setUp() throws Exception {
SelecionarNavegador nav = new SelecionarNavegador();
driver = nav.iniciarNavegador("chrome", "http://10.5.9.45/BkoMais_Selenium/");
}
@Test
public void selecionarFacilidades() throws Exception {
// Logando na aplicação
LogarBkoMaisPage login = new LogarBkoMaisPage(driver);
login.logar("844502", "Bcc201707");
// BackOffice >> FaturamentoGe >> Conectividade
FaturamentoGeConectividadeFacilidadesPage menu = new FaturamentoGeConectividadeFacilidadesPage(driver);
menu.logarFaturamentoGeConectividade();
//Registro >> Novo caso
RegistroNovoCasoPage reg = new RegistroNovoCasoPage(driver);
reg.registrarCaso();
//Preencher campos
FaturamentoGeTratamentoOsPage campo = new FaturamentoGeTratamentoOsPage(driver);
campo.preencherCampoMotivo(" Concluido ");
}
@After
public void tearDown() throws Exception {
Thread.sleep(5000);
driver.quit();
}
}
您需要添加
pagefactory.init
来初始化webelement
public FaturamentoGeTratamentoOsPage(WebDriver driver) { this.driver = driver;
PageFactory.initElements(driver, this);
}
不使用下线。。因为CBOMotive只直接返回一个webelement
WebElement campoMotivo = driver.findElement(By.id(CBOMotivo));
您需要添加
pagefactory.init
来初始化webelement
public FaturamentoGeTratamentoOsPage(WebDriver driver) { this.driver = driver;
PageFactory.initElements(driver, this);
}
不使用下线。。因为CBOMotive只直接返回一个webelement
WebElement campoMotivo = driver.findElement(By.id(CBOMotivo));
您之所以会收到错误,是因为
By.id()
需要字符串,而不是WebElement
。您已将CBOMotivo
定义为WebElement
,但将其视为字符串
以下是正确的用法
WebElement campoMotivo = driver.findElement(By.id("cboMotivo"));
你想要的是
public void preencherCampoMotivo(String CampoMotivo) {
// Campo Motivo
Select slcMotivo = new Select(CBOMotivo);
slcMotivo.selectByVisibleText(CampoMotivo);
}
您之所以会收到错误,是因为By.id()
需要字符串,而不是WebElement
。您已将CBOMotivo
定义为WebElement
,但将其视为字符串
以下是正确的用法
WebElement campoMotivo = driver.findElement(By.id("cboMotivo"));
你想要的是
public void preencherCampoMotivo(String CampoMotivo) {
// Campo Motivo
Select slcMotivo = new Select(CBOMotivo);
slcMotivo.selectByVisibleText(CampoMotivo);
}
CBOMotivo是一个WebElement,当您定义它时,您不需要再次搜索。只使用它。您可以通过id.j.barrio对尝试搜索对象的行进行注释,正如您所说,我对该行进行了注释,Eclipse显示了以下错误消息:java.lang.NullPointerException位于org.openqa.selenium.support.ui.Select。(Select.java:44)位于page.faturamentogetractamentoospage.preenchercompotivo在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处的test.faturamentogeConnectivedFacilidTest.SelecionArfacilidAddress(faturamentogeConnectivedFacilidTest.java:38)处CBOMotivo是一个WebElement,当您定义它时,您不需要再次搜索。只需使用它。您可以通过id.j.barrio对您尝试搜索对象的行进行注释,我如您所说对该行进行了注释,Eclipse在org.openqa.selenium.support.ui.Select上显示以下错误消息:java.lang.NullPointerException。(Select.java:44)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处的test.faturamentogetractionToolsPage.PreencherCompomotivo(faturamentogetractionToolsPage.java:24)页面上,在sun.reflect.NativeMethodAccessorImpl.invoke0处,在.faturamentogetractionToolsPage.PreencherCompositive(faturamentAgetractionToolsPage.java:24)