Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

O meu código está aparecendo esse erro: InvalidSelectorException: invalid selector: An invalid or illegal selector was specified

Bom dia! Não estou conseguindo localizar o erro, pode me ajudar?

` public class LeiloesPage { private static final String URL_CADASTR0_LEILAO = "http://localhost:8080/leiloes/new"; private WebDriver browser;

public LeiloesPage(WebDriver browser) {
     this.browser = browser;
}

public void fechar() {
    this.browser.quit();

}

public CadastroLeilaoPage carregarFormulario() {
 this.browser.navigate().to(URL_CADASTR0_LEILAO);
 return new CadastroLeilaoPage(browser);


}

public boolean isLeilaoCadastrado(String nome, String valor, String data) {
    WebElement linhaDaTabela = this.browser.findElement(By.cssSelector("#tabela-leiloes tbody tr:last-child"));
    WebElement colunaNome = linhaDaTabela.findElement(By.cssSelector("td:nth - child(1)"));
    WebElement colunaDataAbertura = linhaDaTabela.findElement(By.cssSelector("td:nth - child(2)"));
    WebElement colunaValorInicial = linhaDaTabela.findElement(By.cssSelector("td:nth - child(3)"));

    return colunaNome.getText().equals(nome) && colunaDataAbertura.getText().equals(data) && colunaValorInicial.getText().equals(valor);
}

}

public class LeiloesTest {

private LeiloesPage paginaDeLeiloes;


@AfterEach
public void afterEach() {
    this.paginaDeLeiloes.fechar();
}

@Test
public void deveriaCadastrarLeilao() {
    LoginPage paginaDeLogin = new LoginPage();
    paginaDeLogin.preencheFormularioDeLogin("fulano", "pass");
    this.paginaDeLeiloes = paginaDeLogin.efetuaLogin();
    CadastroLeilaoPage paginaDeCadastro = paginaDeLeiloes.carregarFormulario();

    String hoje = LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
    String nome = "Leilao do dia " + hoje;
    String valor = "500.00";


    this.paginaDeLeiloes = paginaDeCadastro.cadastrarLeilao(nome, valor, hoje);
    Assert.assertTrue(paginaDeLeiloes.isLeilaoCadastrado(nome, valor, hoje));
}

}

public class CadastroLeilaoPage {

private WebDriver browser;

public CadastroLeilaoPage(WebDriver browser) {
     this.browser = browser;

}

public void fechar() {
    this.browser.quit();

}

public LeiloesPage cadastrarLeilao(String nome, String valorInicial, String dataAbertura) {
    this.browser.findElement(By.id("nome")).sendKeys(nome);
    this.browser.findElement(By.id("valorInicial")).sendKeys(valorInicial);
    this.browser.findElement(By.id("dataAbertura")).sendKeys(dataAbertura);
    this.browser.findElement(By.id("button-submit")).submit();;

    return new LeiloesPage(browser);
}

}

2 respostas
solução!

Olá Palomaa, tudo certo?

Então analisando seu código, notei essa pequena diferença aqui:

WebElement colunaNome = linhaDaTabela.findElement(By.cssSelector("td:nth - child(1)"));
WebElement colunaDataAbertura = linhaDaTabela.findElement(By.cssSelector("td:nth - child(2)"));
WebElement colunaValorInicial = linhaDaTabela.findElement(By.cssSelector("td:nth - child(3)"));

Note que o nth-child possui espaços entre o hifen. Sugiro que vc remova esses espaços. vai ficar assim:

WebElement colunaNome = linhaDaTabela.findElement(By.cssSelector("td:nth-child(1)"));
WebElement colunaDataAbertura = linhaDaTabela.findElement(By.cssSelector("td:nth-child(2)"));
WebElement colunaValorInicial = linhaDaTabela.findElement(By.cssSelector("td:nth-child(3)"));

Espero ter ajudado!! Um abraço e bons estudos! :-)

Olá Thiago, tudo ótimo e com você?

Muito obrigada, me ajudou muito, deu certo!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software