How to locate a link using page object model after mouse over



  • 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



  • 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.



Suggested Topics