Selenium newbie here... I am trying to create my first test framework .
Test Website : https://www.phptravels.net/
Test Case :
- Open Browser and enter the webpage
- Once the page is loaded , click on MyAccount ->Login
I have used xpath in my page object class and the script will run only till launching the webpage. It fails to click on the Login link .
I have tried to include an implicit wait assuming that the time taken for the page to load is longer than usual . Even then the issue persists.
Can you please help me understand what would be the correct xpath that this will work ?
Code :
POM_HomePage.java
package PageObjects;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class POM_HomePage {
WebDriver driver;
public POM_HomePage(WebDriver driver) {
this.driver=driver;
PageFactory.initElements(driver, this);
}
@FindBy(xpath="//*[@id='li_myaccount']/ul/li[1]/a")
WebElement LinkMyAccount;
public WebElement clickMyAccount() {
return LinkMyAccount;
}
}
HomePage.java
package TestGroupID;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.Test;
import PageObjects.POM_HomePage;
import Resources.MasterScript;
public class HomePage extends MasterScript{
@Test
public void SignIn() throws IOException {
driver=LoadBrowser();
LoadPropFile();
driver.get(prop.getProperty("test_website"));
POM_HomePage pomHome=new POM_HomePage(driver);
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
if (pomHome.clickMyAccount().isDisplayed()) {
pomHome.clickMyAccount().click();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
}
}