-1

I'm trying to do an automated test on Facebook by trying to create an account, but I'm having a problem clicking on the "Create Account" button, I'm trying to use a FindElement by id, but it is not working.

public void criarConta(String nome, String apelido, String email, String password) {

    driver.findElement(By.id("u_0_2_OE")).click();
    
    WebElement nomeElement = driver.findElement(By.name("firstname"));
    
    nomeElement.sendKeys("Teste");
    
    
    WebElement apelidoElement = driver.findElement(By.name("lastname"));
    
    apelidoElement.sendKeys("Alfasoft");
    
    
    WebElement emailElement = driver.findElement(By.name("reg_email__"));
    
    emailElement.sendKeys("fabio.teste@alfasoft.pt");
    
    
    WebElement passwordElement = driver.findElement(By.name("reg_passwd__"));
    
    passwordElement.sendKeys("AlfasoftTeste_");
    
    
    driver.findElement(By.name("birthday_day")).click();
    
    WebElement idElement = driver.findElement(By.id("day"));
    
    idElement.sendKeys("6");
    
    
    driver.findElement(By.name("birthday_month")).click();
    
    WebElement mesElement = driver.findElement(By.id("month"));
    
    mesElement.sendKeys("Ago");
    
    
    driver.findElement(By.name("birthday_year")).click();
    
    WebElement anoElement = driver.findElement(By.id("year"));
    
    anoElement.sendKeys("1999");
    
    
    driver.findElement(By.id("u_h_3_BO")).click();
    
    
    driver.findElement(By.name("websubmit")).click();
    
}

(Im invoking this code in another Class using: public static void main(String[] args) throws Exception and then tarefa2Project.criarConta("nome","apelido","email","password"); ...

mad_lad
  • 654
  • 3
  • 8
  • 20

2 Answers2

0

You could go for the xpath here, use the element attributes and the text to make it unique:

driver.findElement(By.xpath("//a[@role='button'][text()='Create New Account']")).click();
art_architect
  • 919
  • 6
  • 8
0

In order to not be tied to the element's text and not to use xpath you can use the following css selector:
li>a[role='button']

Prophet
  • 32,350
  • 22
  • 54
  • 79