定制的硒xpaths?

时间:2020-04-21 00:25:52

标签: selenium testing xpath automated-tests qa

我需要获取动态路径来删除和更新todo.ly中的项目,我的代码效率不高(我认为),并且我在删除项目时遇到了麻烦,因为google发送的对话消息中没有xpath。

    @Test
public void testSeleniumTestNG() throws InterruptedException, ElementNotInteractableException, StaleElementReferenceException {
    driver.get("https://todo.ly/");
    // click en login
    driver.findElement(By.xpath("//*[@id=\"ctl00_MainContent_PanelNotAuth\"]/div[2]/div[1]/div[2]/a/img")).click();
    // ingresa el email
    driver.findElement(By.id("ctl00_MainContent_LoginControl1_TextBoxEmail")).sendKeys("some email");
    // ingresa la contraseña
    driver.findElement(By.id("ctl00_MainContent_LoginControl1_TextBoxPassword")).sendKeys("some password");
    // click en login
    driver.findElement(By.id("ctl00_MainContent_LoginControl1_ButtonLogin")).click();
    // click en nuevo proyecto
    //driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[1]/div[6]/div")).click();
    // crea un proyecto
    // driver.findElement(By.id("NewProjNameInput")).sendKeys("project");
    // añade el nuevo proyecto
    // driver.findElement(By.id("NewProjNameButton")).click();
    // update un proyecto: ir al control
    driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[1]/div[4]/ul/li[3]/div/table/tbody/tr/td[4]")).getLocation();
    // click en control
    driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[1]/div[4]/ul/li[3]/div/table/tbody/tr/td[4]/div[2]/img")).click();
    //click en edit
    driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/ul[1]/li[1]")).click();
    //editar nombre
    driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[1]/div[4]/ul/li[3]/div/table/tbody/tr/td[3]/div/input")).sendKeys("cambio");
    //guardar
    driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[1]/div[4]/ul/li[3]/div/table/tbody/tr/td[3]/div/img[1]")).click();
    //eliminar un proyecto: ir al control
    driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[1]/div[4]/ul/li[3]/div/table/tbody/tr/td[4]")).getLocation();
    // click en control
    driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[1]/div[4]/ul/li[3]/div/table/tbody/tr/td[4]/div[2]/img")).click();
    //click en edit
    driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/ul[1]/li[1]")).click();
    //editar nombre
    driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[1]/div[4]/ul/li[3]/div/table/tbody/tr/td[3]/div/input")).sendKeys("cambio");
    //borrar
    driver.findElement(By.xpath("/html/body/form/div[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[1]/div[4]/ul/li[3]/div/table/tbody/tr/td[3]/div/img[2]")).click();
    //
    Thread.sleep(2000);

}

0 个答案:

没有答案