Handling right click using Selenium WebDriver
Steps to handle this:
1.Open web browser
2.Get webelement for the object
3.Create an object for Driver
4.From Action object, create context click on to perform Right click on the object
5.Use sendKeys to point arrow to right top line menu, and then move Down/Click
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class SeleniumRhtClickAndWindowsHandles {
@Test
public void rightClickHandles() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://docs.seleniumhq.org/");
Thread.sleep(3000);
WebElement element = driver.findElement(By.cssSelector("#menu_documentation a"));
Actions action = new Actions(driver); //Create an action object for driver
action.contextClick(element).build().perform(); // Right click
action.sendKeys(Keys.ARROW_RIGHT).build().perform();
Thread.sleep(2000);
action.sendKeys(Keys.ARROW_DOWN).build().perform();
Thread.sleep(2000);
action.sendKeys(Keys.ENTER).build().perform();
Thread.sleep(2000);
driver.close();
}
}
Steps to handle this:
1.Open web browser
2.Get webelement for the object
3.Create an object for Driver
4.From Action object, create context click on to perform Right click on the object
5.Use sendKeys to point arrow to right top line menu, and then move Down/Click
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class SeleniumRhtClickAndWindowsHandles {
@Test
public void rightClickHandles() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://docs.seleniumhq.org/");
Thread.sleep(3000);
WebElement element = driver.findElement(By.cssSelector("#menu_documentation a"));
Actions action = new Actions(driver); //Create an action object for driver
action.contextClick(element).build().perform(); // Right click
action.sendKeys(Keys.ARROW_RIGHT).build().perform();
Thread.sleep(2000);
action.sendKeys(Keys.ARROW_DOWN).build().perform();
Thread.sleep(2000);
action.sendKeys(Keys.ENTER).build().perform();
Thread.sleep(2000);
driver.close();
}
}
No comments:
Post a Comment