4

1.go to this URL :->http://wallethub.com/profile/test_insurance_company/

2.On the right part of the page, hover over the stars and click on the fifth star code should actually (1) do the hover and (2) make sure the stars inside get lit up when you hover over them, then (3) click on the fifth star.

The following doesn't work

 import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.interactions.Actions;

public class Wallethub2 {

    /**
     * @param args
     */
    public static void main(String[] args) {

        ProfilesIni prof = new ProfilesIni();
        FirefoxProfile fp = prof.getProfile("sel");

        WebDriver driver=new FirefoxDriver(fp);

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.get("http://wallethub.com/profile/test_insurance_company/");

//      Xpaths of 5 stars
       String star1="//div[@class='wh-rating-choices-holder']/a[contains(@href, '#')][1]";
       String star2="//div[@class='wh-rating-choices-holder']/a[contains(@href, '#')][2]";
       String star3="//div[@class='wh-rating-choices-holder']/a[contains(@href, '#')][3]";
       String star4="//div[@class='wh-rating-choices-holder']/a[contains(@href, '#')][4]";
       String star5="//div[@class='wh-rating-choices-holder']/a[contains(@href, '#')][5]";

        WebElement srating1=driver.findElement(By.xpath(star1));            
        WebElement srating2=driver.findElement(By.xpath(star2));            
        WebElement srating3=driver.findElement(By.xpath(star3));            
        WebElement srating4=driver.findElement(By.xpath(star4));            
        WebElement srating5=driver.findElement(By.xpath(star5));    


        Actions builder = new Actions(driver);  
                builder.moveToElement(srating1).build().perform();
        builder.moveToElement(srating1).build().perform();
        builder.moveToElement(srating2).build().perform();
        srating3.click();








    }

}
3
  • Is the Code doing any of the above tasks? (hover) Commented Nov 18, 2013 at 9:37
  • Is it working? Is it throwing any error? Can you post the logs? Commented Nov 20, 2013 at 6:13
  • Element is not currently visible and so may not be interacted with. Commented Nov 20, 2013 at 6:28

1 Answer 1

5

If you want to click on the fifth star should it be srating5.click()

Or if there is an issue with your code try using:

Locatable hoverItem = (Locatable) driver.findElement(srating1);

Mouse mouse = ((HasInputDevices) driver).getMouse();

mouse.mouseMove(hoverItem.getCoordinates());

To do the hover for the first star then repeat.

The for the last item you should be able to do what you are doing or try

Locatable clickItem = (Locatable)driver.findElement(srating3).getLocation();
clickItem.getCordinates(clickItem).click(); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, 'mouse.mouseMove(hoverItem.getCoordinates());' worked for me to do 'on mouse up' element.

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.