【问题标题】:I'm trying to do an automated test on creating a facebook account我正在尝试对创建 facebook 帐户进行自动化测试
【发布时间】:2021-05-11 11:26:12
【问题描述】:

我正在尝试通过创建帐户在 Facebook 上进行自动化测试,但我在单击“创建帐户”按钮时遇到问题,我正在尝试按 ID 使用 FindElement,但它不工作。

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();
    
}

(我在另一个类中调用此代码:public static void main(String[] args) throws Exception 然后tarefa2Project.criarConta("nome","apelido","email","password"); ...

【问题讨论】:

    标签: javascript selenium selenium-rc


    【解决方案1】:

    您可以在这里使用 xpath,使用元素属性和文本使其唯一:

    driver.findElement(By.xpath("//a[@role='button'][text()='Create New Account']")).click();
    

    【讨论】:

    • @FábioSantos 如果您的 cssSelector 工作正常,那到底是什么问题?
    • 我没有使用 cssSelector
    【解决方案2】:

    为了不绑定到元素的文本并且不使用xpath,您可以使用以下css选择器:
    li>a[role='button']

    【讨论】:

      猜你喜欢
      • 2015-08-02
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-11
      • 2021-07-13
      相关资源
      最近更新 更多