Selenium Java to select an option from the Chrome context menu
KW.java
import java.awt.AWTException; import java.awt.Robot; import java.awt.event.KeyEvent; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; class KW { public static void main(String[] args) throws AWTException { Robot robot = new Robot(); System.setProperty("webdriver.chrome.driver", "/home/kodingwindow/drivers/chromedriver"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.navigate().to("https://kodingwindow.com/testapp/"); WebElement un = driver.findElement(By.name("username")); Actions builder = new Actions(driver); Action multipleActions = builder.moveToElement(un).click().sendKeys(un, "kodingwindow").click(un) .doubleClick(un).contextClick().build(); multipleActions.perform(); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); robot.keyPress(KeyEvent.VK_ENTER); driver.findElement(By.name("password")).sendKeys(Keys.CONTROL, "v"); driver.findElement(By.name("login")).click(); } }
Comments and Reactions
Advertisement