Help needed with a simple website menu click

33 views
Skip to first unread message

Shan Watkins

unread,
Sep 24, 2022, 11:44:49 PM9/24/22
to Selenium Users
I've trying to figure this submenu click, but it somehow goes to a wrong menu. I don't see any code error, not sure what is going on.
Here are the codes:

package selenium.basics;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.interactions.Actions;


public class ChromeTest {


   public static void main(String[] args) {

       

       //Task: Open google.com on Chrome Browser

       String homepage="https://usa.m3.com";

       System.out.println("Registering the driver");

       //Register chrome driver

            System.setProperty("webdriver.chrome.driver","/Users/gd/Downloads/Selenium/drivers/chromedriver");

       

       //Open www.google.com

       WebDriver driver = new ChromeDriver();

       

       //Open url

       System.out.println("Opening web page");

       driver.get(homepage);

       

       //Get title

       String title = driver.getTitle();

       System.out.println("Title:" + title);

       

       String expectedTitle = "Connecting the Healthcare Community | M3 USA";

       

       //Match title

       if(expectedTitle.equals(title)) {

           System.out.println("Title matched..");

       }else {

           System.out.println("Title is not correct");

           }

           

       //Clicking menus

       Actions action = new Actions(driver);

       WebElement integratedSolutionsMenuItem = driver.findElement(By.xpath("//*[@id=\"menu-item-22\"]/a"));

       WebElement attractingSubItem = driver.findElement(By.xpath("//*[@id=\"menu-item-87\"]/a"));

       action.moveToElement(integratedSolutionsMenuItem).click(attractingSubItem).build().perform();

   }

}

Mahantesh Dindawar

unread,
Nov 7, 2022, 9:20:37 AM11/7/22
to Selenium Users
You may need to set Implicit wait to enable your subItem shows up before clicking on it.
Reply all
Reply to author
Forward
0 new messages