2

i am trying to automate amazon.in login, but the mouse hover affect doesn't work. Problem:- i have created two classes declare and calling class. In declaring class i have declared all the elements and in calling class i have called all the elements. But the hover mouse hover doesn't work.

Declaring class

package declaringClassAmazonOrder;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.interactions.Actions;


public class declaringClass {

    WebDriver driver;
    //Actions act=new Actions(driver);
    public declaringClass(WebDriver driver) {
        this.driver=driver;
    }
    //hovering the mouse over login button
    @FindBy(how=How.XPATH, using=("//*[@id='nav-link-yourAccount']"))
    WebElement helloSignIn;

    //clicking on login button
    @FindBy(xpath="//*[@id='nav-flyout-ya-signin']/a/span")
    WebElement signIn;

    //user clicks on email
    @FindBy(id="ap_email")
    WebElement email;

    //user clicks on password
    @FindBy(id="ap_password")
    WebElement password;

    //User clicks on submit 
    @FindBy(id="signInSubmit")
    WebElement login;

    //Selecting Amazon prime check box
    @FindBy(xpath="//*[@id='ref_10440598031']/li/a")
    WebElement prime;

    //Selecting Amazon fulfilled check box
    @FindBy(xpath="//*[@id='ref_10440596031']/li/a")
    WebElement fulFilled;

    //Selecting the product, after selecting the product user needs to switch 
    @FindBy(xpath="//*[@id='result_0']/div/div[2]/div/div/a/img")
    WebElement product;

    //Choose phone color after selecting the product
    @FindBy(xpath="//*[@id='a-autoid-12-announce']/div/div[1]/img")
    WebElement phoneColor;

    //click on add to card button
    @FindBy(xpath="//*[@id='add-to-cart-button']")
    WebElement addToCard;

    //click on proceed to check out button
    @FindBy(xpath="//*[@id='hlb-ptc-btn-native']")
    WebElement proceedToCheckOut;

    //Select delivery address using zip code
    @FindBy(id="searchCriterion.storeZip")
    WebElement zipcodeRadioButton;

    //Enter Zip code
    @FindBy(id="storeZip")
    WebElement enterZipCode;

    //clicking on search buttonx`
    @FindBy(xpath="//*[@id='legacy-non-converged-locker-find']/form/table/tbody/tr[9]/td/div/input")
    WebElement searchButton;

public WebElement helloSignIn1()
    {return helloSignIn;
    }

    public WebElement signIn()
    {System.out.println("page click");
        return signIn;
    }

    public WebElement enterEmail()
    {System.out.println("");
         return email;
    }

    public WebElement enterPassword()
    {
        return password;
    }

    public WebElement loginAmazon()
    {return login;
    }

    public WebElement checkPrime()
    {return prime;
    }

    public WebElement checkfulFilled()
    {return fulFilled;
    }

    public WebElement selectProduct()
    {
        return product;
    }

    public WebElement selectPhoneColor()
    {return phoneColor;
    }

    public WebElement addProductToCart()
    {   
        return addToCard;
    }

    public WebElement checkOut()
    {return proceedToCheckOut;
    }

    public WebElement checkZipCodeRadioButton()
    {return zipcodeRadioButton;
    }

    public WebElement enterZipCodeValue()
    {return enterZipCode;
    }

    public WebElement clickSearchButton()
    {return searchButton;
    }
}


package callingClass1;
import declaringClassAmazonOrder.declaringClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.interactions.Actions;
import BrowserToOrder.selectBrowser;

public class callingClass {
    @Test()
    public void orderProduct() throws InterruptedException
    {   
        System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        Actions ac= new Actions(driver);
        driver.manage().window().maximize();
        driver.get("https://www.amazon.in");
        declaringClass dc=new declaringClass(driver);
        PageFactory.initElements(driver,declaringClass.class);  
        Thread.sleep(1000);
        System.out.println("before mouse hover");
        ac.moveToElement(dc.helloSignIn1()).build().perform();
        Thread.sleep(1000);
        System.out.println("after mouse hover");

    /*  wd.until(ExpectedConditions.elementToBeClickable(dc.signIn())).click();
        dc.signIn().click();
        dc.enterEmail().sendKeys("[email protected]");
        dc.enterPassword().sendKeys("anc");
        dc.loginAmazon().click();
        dc.checkPrime().click();
        dc.checkfulFilled().click();
        dc.selectProduct().click();
        dc.selectPhoneColor().click();
        dc.checkOut().click();
        dc.checkZipCodeRadioButton().click();
        dc.enterZipCodeValue().sendKeys("123456");
        dc.clickSearchButton().click();
        */
    }
}
4
  • Does your code throws any error during execution? Commented Feb 9, 2017 at 3:44
  • Go for Javascript MouseOver as I have tested and it's working for Amazon Commented Feb 9, 2017 at 5:04
  • No, the code doesn't throw any error, but it works fine till "before mouse hover statement" Commented Feb 10, 2017 at 3:11
  • Thanks Madhan :), will try and check that Commented Feb 10, 2017 at 3:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.