If all you want is the text, you can get it by using .getText()
on the right element.
WebDriver driver = new FirefoxDriver();
driver.get("http://connectatgrace.org/im-new/what-to-expect");
String text = driver.findElement(By.id("main")).getText().trim();
EDIT
I understand now what you are looking for. I was able to get it to work with the code below.
Basically the code moves the mouse to the bottom-right corner of the element that contains all the desired text, <div id="content full-width">
. Click and hold the mouse button down, move to the top-left corner of the element, and then CTRL+C
. I've also validated that the correct text gets into the clipboard.
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://connectatgrace.org/im-new/what-to-expect");
WebElement content = driver.findElement(By.id("content full-width"));
Actions builder = new Actions(driver);
builder.moveToElement(content, 0, 0).clickAndHold().moveToElement(content,
content.getSize().getWidth(), content1.getSize().getHeight()).release();
builder.build().perform();
content.sendKeys(Keys.chord(Keys.CONTROL, "c"));
System.out.println("CLICKED");
NOTE: If you use moveToElement()
, it moves to the center of the element. That's why there's code to get the width/height and divide by 2.
EDIT 2
After OP noticed that I had a typo, I went back and did some investigations on the .moveToElement()
methods. From the docs,
moveToElement(WebElement toElement)
Moves the mouse to the middle of the element.
moveToElement(WebElement toElement, int xOffset, int yOffset)
Moves the mouse to an offset from the top-left corner of the element.
So corrected the code to use .moveToElement(e, 0, 0)
to start the selection at the top left of the element and then moved the selection to the bottom right using .moveToElement(content, content.getSize().getWidth(), content1.getSize().getHeight())
. This should work correctly now.