Creating Highlight in Selenium Webdriver

1.1k Views Asked by At

I need to select a group of text in a web page by clicking the left click of the mouse. When I release the left click, one menu apppears. How to select the group of text in Selenium?

1

There are 1 best solutions below

9
On

Try this:

public class SelectText {

    public static void main(String[] args) {
        WebDriver driver=new FirefoxDriver();
        driver.get("https://www.google.co.in");
        driver.manage().window().maximize();
        WebElement element = driver.findElement(By.xpath("html/body/div[1]/div[5]/span/center/div[3]/div/div"));
        Actions actions = new Actions(driver);
        actions.moveToElement(element, 0, 0)
            .clickAndHold()
            .moveByOffset(50, 0)
            .release()
            .perform();
    }

}

1)Here I am trying to select Google text that is below the search button

2)I am finding the element and then moving to the element at position (0,0)which is the top left corner of the element,

3)By using click and hold I am moving to the right using moveByOffset function by 50, you can vary x and y parameters of moveByOffset function based on your text selection area.

Hope it helps