Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select a text and perform a click action

I'd like to select some text and perform a click action - like in Winword where we click Bold after selecting some text...

I have to select the text and click on the <B> bold icon in the textarea.

Any idea on how to do this using Selenium/Webdriver?

like image 951
smriti Avatar asked Apr 02 '12 14:04

smriti


2 Answers

In Java, The Advanced User Interactions API has your answer.

// the element containing the text
WebElement element = driver.findElement(By.id("text"));
// assuming driver is a well behaving WebDriver
Actions actions = new Actions(driver);
// and some variation of this:
actions.moveToElement(element, 10, 5)
    .clickAndHold()
    .moveByOffset(30, 0)
    .release()
    .perform();
like image 100
Petr Janeček Avatar answered Oct 21 '22 18:10

Petr Janeček


I tried with Action builder and played with offset. It worked for me.

Actions action = new Actions(driver);
action.moveToElement(wblmt,3,3).click().keyDown(Keys.SHIFT).moveToElement(wblmt,200, 0).click().keyUp(Keys.SHIFT).build().perform(); 
like image 36
Siju Vasu Avatar answered Oct 21 '22 18:10

Siju Vasu