Example usage for org.openqa.selenium.interactions Actions moveToElement

List of usage examples for org.openqa.selenium.interactions Actions moveToElement

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions moveToElement.

Prototype

public Actions moveToElement(WebElement target) 

Source Link

Document

Moves the mouse to the middle of the element.

Usage

From source file:TBR.Regression_Testcases.CreateNewCandidate.java

@Test(dataProvider = "getCreateNewCandidateData")
public void createNewCandidate(Hashtable<String, String> data) throws InterruptedException {
    openBrowser();/*from  w ww.ja v  a  2  s  .  c o m*/
    driver.get(CONFIG.getProperty("testSiteName"));
    login_Valid();
    //login_Kevin();
    getObject("candLinkX").click();
    getObject("addNewCandidateX").click();
    waitForElementClickableId(10, "candidateNameId");
    //waitForElementClickableId(10, "candidateNameId");

    //moves on to step 1 Basic Information
    //explicitWaitId("candidateNameId");
    getObjectById("candidateNameId").sendKeys(data.get("CandidateName"));
    Thread.sleep(5000);
    String candidateName = getObjectById("candidateNameId").getAttribute("value");
    System.out.println("name of the new candidate is= " + candidateName);
    getObjectById("candidateEmailId").sendKeys(data.get("CandidateEmail"));
    getObjectById("candidatePhoneNumberId").sendKeys(data.get("PhoneNumber"));
    /*getObject("candidateMonthX").sendKeys(data.get("DobMonth"));
    //getObjectById("candidateYearX").click();
    getObject("candidateYearX").sendKeys(data.get("DobYear"));
    getObject("candidateDayDateX").click();*/
    getObjectById("candidateDobId").click();
    Thread.sleep(5000);
    Select yearDob = new Select(getObject("candidateYearX"));
    yearDob.selectByValue("2009");
    Select monthDob = new Select(getObjectByCss("candidateMonthCSS"));
    monthDob.selectByVisibleText("Oct");
    getObject("candidateDayDateX").click();
    getObjectById("candidateAddressId").click();
    getObjectById("candidateAddressId").sendKeys(data.get("CandidateAddress"));
    Actions hover = new Actions(driver);
    WebElement elementToHover = getObject("candidateNextStep1X");
    hover.moveToElement(elementToHover);
    hover.build().perform();
    Thread.sleep(3000);
    getObject("candidateNextStep1X").click();

    //moving on to Step 2 LogIn Details
    getObjectById("candidateUsernameId").sendKeys(data.get("CandidateUsername"));
    getObjectById("candidatePasswordId").sendKeys(data.get("CandidatePassword"));
    Actions hove = new Actions(driver);
    WebElement elementToHov = getObject("candidateNextStep1X");
    hove.moveToElement(elementToHov);
    hove.build().perform();
    //getObjectByCss("candidateNextStepCss").click();

    Actions hover3 = new Actions(driver);
    WebElement elementToHover3 = getObjectByCss("candidateNextStepCss");
    hover3.moveToElement(elementToHover3);
    hover3.build().perform();
    Thread.sleep(4000);
    getObjectByCss("candidateNextStepCss").click();
    System.out.println("clicked on next in step 2");

    //moving on to Step 3 Employment Information
    waitForElementClickableId(10, "candidateNiNumberId");
    getObjectById("candidateNiNumberId").sendKeys(data.get("NiNumber"));
    getObjectById("candidateStatusId").sendKeys(data.get("CandidateStatus"));
    getObject("candidateNextStep3X").click();

    //moving on to Step 4 Social Media (Optional)
    getObjectById("candidateFacebookId").sendKeys(data.get("Facebook"));
    getObjectById("candidateTwitterId").sendKeys(data.get("Twitter"));
    getObjectById("candidateLinkedinId").sendKeys(data.get("LinkedIn"));
    getObjectById("candidateSkypeId").sendKeys(data.get("Skype"));
    getObject("candidateNextStep4X").click();

    //moving on to Step 5 Criteria
    getObject("candidateCategoryX").click();
    getObject("candidateCategoryX").sendKeys(data.get("Category"));
    getObject("candidateCategoryX").sendKeys(Keys.RETURN);
    //Thread.sleep(3000);
    /*the below two lines are for live server*/
    //getObjectById("candidateLicenseId").click();
    //getObjectById("candidateLicenseId").sendKeys(data.get("driverlicense"));
    //getObjectById("candidateLicenseId").sendKeys(Keys.RETURN);
    /*end of live server code*/
    getObject("candidateCustomAttributeShowX").click();
    explicitWaitId("candidatePassportId");
    getObjectById("candidatePassportId").click();
    Select month = new Select(getObject("candidatePassportMonthX"));
    month.selectByVisibleText("Oct");
    Select year = new Select(getObject("candidatePassportYearX"));
    year.selectByValue("2020");
    getObject("candidatePassportDateX").click();
    Thread.sleep(5000);
    getObjectById("candidateManualCertId").click();
    Select month1 = new Select(getObject("candidateManualMonthX"));
    month1.selectByVisibleText("Jul");
    Select year1 = new Select(getObject("candidateManualYearX"));
    year1.selectByValue("2015");
    getObject("candidateManualDateX").click();
    getObjectById("candidateGardaVettingId").sendKeys(data.get("GardaVetting"));
    getObjectById("candidateTrainingId").sendKeys(data.get("TrainingComplete"));
    getObjectById("candidateProofOfRightToWorkId").sendKeys(data.get("ProofRightToWork"));
    getObjectById("candidateCertificationExpiry").click();
    Select month2 = new Select(getObject("candidateCertificationMonthX"));
    month2.selectByVisibleText("Sep");
    Select year2 = new Select(getObject("candidateCertificationYearX"));
    year2.selectByValue("2018");
    getObject("candidateCertificationDateX").click();
    getObject("candidateFinishStep5X").click();
    Thread.sleep(10000);
    explicitWaitXpath("candLinkX");
    //back to dash board
    //getObject("candLinkX").click();
    //explicitWaitXpath("allCandidatesX");
    getObject("allCandidatesX").click();
    //moves on to candidate list wizard
    //explicitWaitXpath("searchCandidateX");
    getObject("searchCandidateX").click();
    //explicitWaitXpath("searchCandidateX");
    getObject("searchCandidateX").sendKeys(candidateName);

    //explicitWaitXpath("candidateMatchX");
    Thread.sleep(5000);
    String candidateNameAppeared = getObject("candidateMatchX").getText();
    System.out.println("candidate appeared on the screen is = " + candidateNameAppeared);
    Assert.assertEquals(candidateNameAppeared, candidateName);
    System.out.println("new candidate saved successfully");
}

From source file:theTests.ShoppostSignUpFB.java

License:Open Source License

@Test
public void test_signUpInFB() throws Exception {
    wait = new WebDriverWait(driver, 10);
    Random rand = new Random();

    ReadTestJSON.read();//from  w  ww .  jav  a 2 s.  com
    _td = ReadTestJSON.get_td();

    String _browsName = this.browser;
    _browsName = _browsName.substring(1);
    ScreenShots ss = new ScreenShots(driver, _td, _sld, _ltd, _browsName, m); //screenshot of platform signup

    signup = new SignUpIn(driver, _td); //signup methods
    SignOut logout = new SignOut(driver);

    _usernameFB = _td.getUsernameFB();
    _passkeyFB = _td.getPasswordFB();
    _username = _td.getUsername();
    _freshUser = "";

    //System.out.println("testLength is: "+TestRunner.getTests().length);
    for (int k = 0; k < _td.getSignupinFBTests().getTests().size(); k++) { //taking one testCase parameter at a time (this by-passes the need for TestRunner
        //for (int k=0; k<TestRunner.getTests().length; k++) {  //taking one testCase parameter at a time from cmd line
        //for (int k=0; k<1; k++) {   //just a quick test
        //ss.takeTheShot(1, "platform");
        //_testCase = TestRunner.getTests()[k];
        _testCase = _td.getSignupinFBTests().getTests().get(k);
        //_testCase = "signupValid";
        switch (_testCase) {

        case "signupValidFB": //not initially signed into FB
            signup.helloPlatform(_td.getBaseUrl());
            _password = _passkeyFB;

            signupinPage = PageFactory.initElements(driver, SignUpSignIn.class); //instantiate the pageOject 

            signupinPage.signupFB(_usernameFB, _passkeyFB);
            FBone = PageFactory.initElements(driver, FBsignIn.class); //instantiate the pageOject 

            FBone.signupNow(_usernameFB, _password);

            FBtwo = PageFactory.initElements(driver, FBsignIn.class); //instantiate the pageOject 

            FBtwo.confirmInfo();

            signupinPage = PageFactory.initElements(driver, SignUpSignIn.class); //instantiate the pageObject

            signupinPage.register(_username);

            catalog = PageFactory.initElements(driver, ProductCatalog.class); //instantiate the pageOject 
            _emailAddress = catalog.getEmailAddress();

            if (_emailAddress.equals(_username)) {
                System.out.println("PASS Correct signin email: " + _username);
            } else {
                fail("Fail - bad email address: " + _emailAddress);
            }

            Thread.sleep(2000);
            logout.logoutFromCat();

            break;

        case "signupValidNoPreFB": //initially signed into FB
            signup.helloPlatform(_td.getBaseUrl());
            _password = _passkeyFB;

            signupinPage = PageFactory.initElements(driver, SignUpSignIn.class); //instantiate the pageOject 

            signupinPage.signupFB(_usernameFB, _passkeyFB);
            //FBone = PageFactory.initElements(driver, FBsignIn.class);  //instantiate the pageOject 

            //FBone.signupNow(_usernameFB, _password);

            FBtwo = PageFactory.initElements(driver, FBsignIn.class); //instantiate the pageOject 

            FBtwo.confirmInfo();

            signupinPage = PageFactory.initElements(driver, SignUpSignIn.class); //instantiate the pageObject

            signupinPage.register(_username);

            catalog = PageFactory.initElements(driver, ProductCatalog.class); //instantiate the pageOject 
            _emailAddress = catalog.getEmailAddress();

            if (_emailAddress.equals(_username)) {
                System.out.println("PASS Correct signin email: " + _username);
            } else {
                fail("Fail - bad email address: " + _emailAddress);
            }

            Thread.sleep(2000);
            logout.logoutFromCat();

            break;

        case "shareModalTest": //initially signed into FB
            signup.helloPlatform(_td.getBaseUrl());
            Actions move = new Actions(driver);
            catalog = PageFactory.initElements(driver, ProductCatalog.class); //instantiate the pageOject 

            int _productCount = catalog.getProductCount();
            move.moveToElement(catalog.hoverRandomProduct());
            catalog = PageFactory.initElements(driver, ProductCatalog.class); //instantiate the pageOject 
            catalog.getShare();
            Thread.sleep(2000);
            //logout.logoutFromCat();

            break;

        case "signinBlankEmail":

            signup.helloPlatform(_td.getBaseUrl());
            _password = _passkey;
            signup.signInTest("", _password, 0);
            Thread.sleep(1000);
            signupinPage = PageFactory.initElements(driver, SignUpSignIn.class); //instantiate the pageOject to include error messages

            _errorMsg = signupinPage.checkEmailError();
            if (_errorMsg.equals("The Email address field is required.")) {
                System.out.println("PASS Correct error advisory: " + _errorMsg);
            } else {
                fail("Fail - requires blank email error advisory not: " + _errorMsg);
            }

            break;

        case "signinEmailBlankPW":
            signup.helloPlatform(_td.getBaseUrl());
            _email = _username;

            _password = _passkey;
            signup.signInTest(_email, "", 0);

            signupinPage = PageFactory.initElements(driver, SignUpSignIn.class); //instantiate the pageOject

            _errorMsg = signupinPage.getRedAdvisory();
            if (_errorMsg.equals("The Password field is required.")) {
                System.out.println("PASS Correct error advisory: " + _errorMsg);
            } else {
                fail("FAIL - requires blank password error advisory not: " + _errorMsg);
            }

            break;

        case "signinInvalidEmail":
            signup.helloPlatform(_td.getBaseUrl());
            _password = _passkey;
            signup.signInTest("ii", _password, 0);
            Thread.sleep(1000);
            signupinPage = PageFactory.initElements(driver, SignUpSignIn.class); //instantiate the pageOject for errors

            _errorMsg = signupinPage.checkEmailError();
            if (_errorMsg.equals("Must be a valid email address.")) {
                System.out.println("PASS Correct error advisory: " + _errorMsg);
            } else {
                fail("FAIL - requires invalid email error advisory not: " + _errorMsg);
            }

            break;

        case "signinBadUsernameBadPW":
            signup.helloPlatform(_td.getBaseUrl());
            _email = "com" + _username; //bad email
            _password = _passkey;
            signup.signInTest(_email, _password, 0);

            signupinPage = PageFactory.initElements(driver, SignUpSignIn.class); //instantiate the pageOject
            Thread.sleep(1000);
            _errorMsg = signupinPage.getRedAdvisory();
            if (_errorMsg.equals("The email address or password is incorrect.")) {
                System.out.println("PASS Correct error advisory: " + _errorMsg);
            } else {
                fail("FAIL - requires bad username or password advisory not: " + _errorMsg);
            }

            break;

        case "userAgreement":
            Window win = new Window(driver);

            signup.helloPlatform(_td.getBaseUrl());
            r = rand.nextInt(10000);
            _email = _username + r + "@sharklasers.com"; //make fake email with random number (a brand new user)_email = _username+r+".com";  //make fake email with random number
            _password = _passkey + _passkey;
            signup.gotoSignup();
            signupinPage = PageFactory.initElements(driver, SignUpSignIn.class); //instantiate the pageOject

            //signinPage.toAgreement();  

            userAgreementPage = PageFactory.initElements(driver, UserAgreement.class);

            wait.until(ExpectedConditions
                    .visibilityOfElementLocated(By.xpath("//label[@for='agreementCheckbox']")));
            _currUrl = driver.getCurrentUrl(); //

            String mwh = driver.getWindowHandle(); //get current window name
            driver.switchTo().window(win.changeWindow(By.xpath("//label[@for='agreementCheckbox']/p/a")));

            try {

                wait.until(
                        ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='container']"))); //wait for user agreement to show
                assertEquals("Shoppost - End User License Agreement", driver.getTitle());
                System.out.println("User Agreement confirmed.");
            } catch (TimeoutException e) {
                System.out.println("NO Agreement Page!");
            } catch (ComparisonFailure ex) {

                System.out.println("Different Error Message Found");
            } finally {
                driver.close();
            }

            //Thread.sleep(1000);
            //driver.close(); //close agreement window

            driver.switchTo().window(mwh); //go back to signup page
            driver.get(_currUrl);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("signUpBtn"))); //waiting for sign up page

            break;

        case "forgotPassword":
            signup.helloPlatform(_td.getBaseUrl() + "sign-up");
            wait.until(ExpectedConditions
                    .visibilityOfElementLocated(By.xpath("//section[@class='form']/footer/p[1]")));
            driver.findElement(By.xpath("//section[@class='form']/footer/p[1]/a")).click();
            Thread.sleep(500);

            try {
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("loginBtn"))); //waiting for sign up page
                driver.findElement(By.id("email_input"));
                System.out.println("Member redirect confirmed.");
            } catch (TimeoutException e) {
                System.out.println("ERROR! No Sign In Page!");
            } catch (ElementNotVisibleException ex) {

                System.out.println("ERROR! Email input not found");
            } finally {
            }
            driver.get(_td.getBaseUrl() + "/sign-up");
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("signUpBtn"))); //waiting for sign up page
            //driver.close();
            break;

        case "signUp":
            signup.helloPlatform(_td.getBaseUrl() + "sign-up");
            wait.until(ExpectedConditions
                    .visibilityOfElementLocated(By.xpath("//section[@class='form']/footer/p[1]")));
            driver.findElement(By.xpath("//section[@class='form']/footer/p[1]/a")).click();
            Thread.sleep(500);

            try {
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("loginBtn"))); //waiting for sign up page
                driver.findElement(By.id("email_input"));
                System.out.println("Member redirect confirmed.");
            } catch (TimeoutException e) {
                System.out.println("ERROR! No Sign In Page!");
            } catch (ElementNotVisibleException ex) {

                System.out.println("ERROR! Email input not found");
            } finally {
            }
            driver.get(_td.getBaseUrl() + "/sign-up");
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("signUpBtn"))); //waiting for sign up page
            //driver.close();
            break;

        case "getHelp":
            signup.helloPlatform(_td.getBaseUrl() + "sign-up");
            wait.until(ExpectedConditions
                    .visibilityOfElementLocated(By.xpath("//section[@class='form']/footer/p[1]")));
            driver.findElement(By.xpath("//section[@class='form']/footer/p[1]/a")).click();
            Thread.sleep(500);

            try {
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("loginBtn"))); //waiting for sign up page
                driver.findElement(By.id("email_input"));
                System.out.println("Member redirect confirmed.");
            } catch (TimeoutException e) {
                System.out.println("ERROR! No Sign In Page!");
            } catch (ElementNotVisibleException ex) {

                System.out.println("ERROR! Email input not found");
            } finally {
            }
            driver.get(_td.getBaseUrl() + "/sign-up");
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("signUpBtn"))); //waiting for sign up page
            //driver.close();
            break;

        }
    }

    Thread.sleep(1000);
    //ss.takeTheShot(2, "platform", _testCase);  //screenshot of outro
    Thread.sleep(1000);

}

From source file:uk.ac.ebi.atlas.acceptance.selenium.pages.HeatmapTablePage.java

License:Apache License

protected void hoverOnElement(WebElement webElement) {
    Action builder;// w  ww .ja  va2 s  . c  o  m
    Actions hover = new Actions(driver);
    hover.moveToElement(webElement);
    builder = hover.build();
    builder.perform();
}

From source file:work_day3.mouseHoveroverProduct.java

@Test
public void mouseOver() throws InterruptedException {
    Thread.sleep(3000);// ww w. j  a  va2 s.  co  m
    getDriver().manage().window().maximize();
    WebElement ele1 = getDriver()
            .findElement(By.xpath("html/body/div[1]/header/div[1]/div/div/div/div/nav/ul/li[1]/a"));

    Actions action = new Actions(getDriver());
    action.moveToElement(ele1).build().perform();
    Thread.sleep(2000);

    WebElement ele2 = getDriver()
            .findElement(By.xpath("html/body/div[1]/header/div[1]/div/div/div/div/nav/ul/li[1]/ul/li[3]/a"));
    action.moveToElement(ele2).build().perform();
    Thread.sleep(2000);

    getDriver().findElement(By.xpath(
            "html/body/div[1]/header/div[1]/div/div/div/div/nav/ul/li[1]/ul/li[3]/ul/li[6]/ul[2]/li[2]/a"))
            .click();
    Thread.sleep(2000);

    getDriver().findElement(By.xpath("html/body/div[4]/header/div[1]/div/div/div/div/nav/ul/li[4]/a")).click();

    getDriver().findElement(By.id("email")).sendKeys("vinod@gmail.com");
    getDriver().findElement(By.id("license")).sendKeys("vinod vinod");

    String output = getDriver().findElement(By.xpath(".//*[@class='submit-error m-bottom-30']")).getText();
    String input = "ERROR: Invalid e-mail or license number";
    Assert.assertEquals(output, input);
    Thread.sleep(1000);
}

From source file:wsjformtest.Wsjformtest.java

/**
 * @param args the command line arguments
 *///from   w  w  w  .ja  v a 2 s.  c om

public static void main(String[] args) throws InterruptedException {
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    driver.get("http://wsj_staging:4%b(q$tm@wsj-staging.developspa.com");
    Thread.sleep(3000);
    driver.findElement(By.name("w2lsubmit")).click();

    //Required_Validation();

    driver.findElement(By.name("w2lsubmit")).click();

    Thread.sleep(3000);

    String text = driver.findElement(By.id("sf_first_name"))
            .findElement(By.xpath("./following-sibling::span[@class='error_message']")).getText();

    Assert.assertTrue(text.equals("This field is required."), "working");

    System.out.print("required field validation works\n");

    Thread.sleep(3000);

    driver.findElement(By.id("sf_first_name")).sendKeys("Meet");

    driver.findElement(By.id("sf_email")).sendKeys("meet@2006");
    Thread.sleep(3000);

    WebElement element = driver.findElement(By.name("w2lsubmit"));
    Actions action = new Actions(driver);
    action.moveToElement(element).click().perform();

    Thread.sleep(1500);

    String Emailtext = driver.findElement(By.id("sf_email"))
            .findElement(By.xpath("./following-sibling::span[@class='error_message']")).getText();

    Assert.assertTrue(Emailtext.equals("The email address you entered is not valid."), "working");

    System.out.print("Email Id validation works\n");

    Thread.sleep(3000);

    driver.findElement(By.id("sf_first_name")).sendKeys("Meet");
    driver.findElement(By.id("sf_email")).clear();
    driver.findElement(By.id("sf_email")).sendKeys("meet2006@gmail.com");
    driver.findElement(By.id("sf_phone")).sendKeys("1111111111");
    driver.findElement(By.id("sf_description")).sendKeys("Test Message");

    WebElement element1 = driver.findElement(By.name("w2lsubmit"));
    Actions action1 = new Actions(driver);
    action1.moveToElement(element1).click().perform();

    Thread.sleep(1500);
    String Formtext = driver.findElement(By.id("salesforce_w2l_lead_1"))
            .findElement(By.xpath("./strong[@class='success_message']")).getText();

    Assert.assertTrue(Formtext.equals("Your message has been submitted successfully."), "working");

    System.out.print("Form submit works\n");

}