Total Pageviews

Tuesday, 18 December 2018

How to do ctrl+f in selenium

There are various ways to press keys in selenium like by using Keys class in send keys or using action class to press keys or using Robot class to simulate key press.

Lets see how we can do this using action class in selenium.

       System.setProperty("webdriver.chrome.driver","C:\\Z_Drivers\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com/");
        WebElement ele = driver.findElement(By.cssSelector("body"));
        Actions action = new Actions(driver);
        action.keyDown(Keys.CONTROL).sendKeys(ele,Keys.chord("f")).keyUp(Keys.CONTROL).perform();


 Note: There are bugs which are still open for some browser version where Keys.chord does not work in that case you will have to use robot class to simulate key presses.

Save Water | Save Energy | Save Earth     
    Stop Pollution | Stop Plastic
                 Spread Peace

No comments:

Post a Comment