lundi 29 juin 2015

Using @FindBy to find an element. Is using XPATH okay?

I currently have this method in my selenium framework.

public void selectAddProductButton() {
    driver.findElement(By.id("Content")).findElement(By.className("Title")).findElement(By.tagName("a")).click();
}

However, I like it and I don't like it. I feel like this is a dirty way to approaching this. I thought it would be better to use @FindBy but I don't see how I could. I usually use @FindBy for more simple things. An example would be

@FindBy(id = "firstname")
private WebElement firstName;

I've read online that I can achieve this by using the @FindBy with an xpath. However, I've also read that using xpath this way is a bad practice. Is there a better way I can do this?

Aucun commentaire:

Enregistrer un commentaire