Ans- To move the pointer with the cursor we have to use the Robot class.
Ex-
import java.awt.AWTException;
import java.awt.Robot;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Myntra {
public static void main(String[] args) throws InterruptedException, AWTException, IOException {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.navigate().to("http://www.myntra.com/");
WebElement women = driver.findElement(By.xpath("//div[@class='head']//a[4][@href='/shop/women?src=tn&nav_id=34']"));
Point coordinate = women.getLocation();
Robot robot = new Robot();
robot.mouseMove(coordinate.getX()+30, coordinate.getY()+120);
Thread.sleep(10000);
driver.findElement(By.xpath("//a[@href='/women-jeans?src=tn&nav_id=48']")).click();
driver.findElement(By.xpath("//div[@id='login']//div[@class='close']")).click();
}
}
Ex-
import java.awt.AWTException;
import java.awt.Robot;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Myntra {
public static void main(String[] args) throws InterruptedException, AWTException, IOException {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.navigate().to("http://www.myntra.com/");
WebElement women = driver.findElement(By.xpath("//div[@class='head']//a[4][@href='/shop/women?src=tn&nav_id=34']"));
Point coordinate = women.getLocation();
Robot robot = new Robot();
robot.mouseMove(coordinate.getX()+30, coordinate.getY()+120);
Thread.sleep(10000);
driver.findElement(By.xpath("//a[@href='/women-jeans?src=tn&nav_id=48']")).click();
driver.findElement(By.xpath("//div[@id='login']//div[@class='close']")).click();
}
}
No comments:
Post a Comment