0

When I hover over login text there are list of links, i need to select Infostore using Page Object model approach. I am new to Selenium could any one help. I have the outer HTML for you:

<div class="desktop-login">
     LOGIN
     <ul class="no-bullet list-nav-child sub-menu-lv">
         <li class="nav-child-item">
             <a href="https://infostore.saiglobal.com/">Infostore</a> 
         </li>
     </ul>
</div>

enter image description here

bumped to the homepage by Community 11 hours ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

You can create classes like this,

Your POM class something look like this:-

 public class Homepage{
  WebDriver driver;
  public Homepage(WebDriver driver) {
        //super();
        this.driver = driver;
    }
        private static final By loginLink= By.linkText("LOGIN");
        private static final By infostoreLink= By.linkText("Infostore");

      public void clickInfostoreLink() { 
          WebElement element= driver.findElement(loginLink);
          Actions action= new Actions(driver);
          action.moveToElement(element);
          action.build().perform();
          driver.findElement(infostoreLink).click();
    }
    }  

Your Test class like this:-

public class LoginTest extends BaseTest {
@Test()
  public void infostoreTest() {
Homepage add= new Homepage(driver);
add.clickInfostoreLink();

//Whatever you want to test according to your test case

}
}  

and BaseTest class look like this:-

public class BaseTest { 
public static WebDriver driver; 

@BeforeTest
  public void LaunchApplication() 
  {
System.setProperty("webdriver.chrome.driver", "C:\\Intel\\chromedriver.exe");
      driver= new ChromeDriver();
driver.get(baseURL);
      driver.manage().window().maximize();
}

 @AfterTest
  public void closeApplication()
  {
      driver.quit();
  }
}  

hope this will help you to get some idea about POM.

0

It's simply a question of breaking the action from high levels of abstraction to the lower ones:

Test:

homePage.selectLoginOption("Infostore");

Home Page:

NextPageAfterClickOnTheOption selectLoginOption(String option) {
   desktopLogin.open();
   return desktopLogin.selectOption(option); // you can do .open().selectOption(option)
}

DesktopLogin:

DesktopLogin open() {
  loginListButton.click(); // or do the hovering
  new WebDriverWait(driver, 1).until(
            ExpectedConditions.visibilityOf(loginList)
  );
  return this;
}

NextPageAfterClickOnTheOption selectOption(String option) {
   loginList.getOptionNamed(option).click();
   return new NextPageAfterClickOnTheOption();
}

LoginList

WebElement getOptionNamed(String optionName) {
   return options.stream()   // convert list to stream
            .filter(option -> optionName.equals(option.getText())) // Just take the options named as the argument we passed
            .findFirst().get() // I am just interested in the first result
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.