Action class click().build.perform(); does not load a new page

I have used the website http://store.demoqa.com/ to practice automation using Selenium Webdriver – Java.

I am automating the following scenario

1. Hover on Product category menu
2. Click on Accessories sub menu – The Accessories Page is loaded
3. Check if the title of the Accescories page matches with the expected title

I used Action class and was able to go upto clicking of the Accessories sub menu.
However,when running the test .I can see the clicking being done by the driver but it  does not load the Accessories Page at all and hence the test fails due to TimeOut Exception.
I have tried using click(), clickAndHold() as well as doubleclick() but none works.

Code is given below
WebDriverWait myWaitvar = new WebDriverWait (driver, 10);
Actions action = new Actions (driver);
WebElement mainMenu = driver.findElement(By.id(“menu-item-33”));
action.moveToElement(mainMenu);
WebElement subMenu = driver.findElement(By.id(“menu-item-34”));
action.moveToElement(subMenu).click(subMenu).build().perform();
myWaitvar.until(ExpectedConditions.elementToBeClickable(By.xpath(“/html/body/div[2]/div/div/div/div/div[1]/article/div/div/div[3]/div[2]/h2/a”)));
//This is to wait till this element is visible on the page
What is the issue with the code above and how can the click load the Accessories page?

Default Asked on February 8, 2016 in Selenium WebDriver.
Add Comment
  • 3 Answer(s)

    where is action.moveToElement(mainMenu).build().perform()?

    Virender

    Professor Answered on February 8, 2016.
    Add Comment

    Hi,

    Try with this code,hope it works fine.. i just wrote the code ,haven’t executed.

    public static void main(string[] args){
    webDriver driver;
    driver=new firefoxDriver();
    driver.get(“http://store.demoqa.com/”);
    driver.manage.window().maximize();
    driver.manage.timesout().implicitwait(20,Timeunits.Seconds);
    WebElement x= driver.findelement(By.xpath(“//a[@href=’http://store.demoqa.com/products-page/product-category/’]”));

    WebElement y= driver.findelement(By.xpath(“//a[@href=’http://store.demoqa.com/products-page/product-category/accessories/’]”));

    Actions a=new Action();
    a.moveToElement(x).moveToElement(y).click.build().perform();
    String act_title=Accessories|ONLINE STORE;
    String exp_title=driver.getCurrentTitle();
    Assert.assertequals(act_title,exp_title);
    System.out.println(“Success,the actual and the expected titles matched”);
    driver.close();
    }

    Train Answered on February 11, 2016.
    Add Comment

    Hi,
    Yes I tried having both the webelements on the same line and its working perfectly fine. Also I realised that the xpath that I was using was of a div and not the link,hence replaced with linkText. Now its working

    Thank you so much for your responses!

    Default Answered on February 27, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.