2014-02-07 96 views
0

在Java中使用Selenium webdriver如何调整文本区域大小/ 我想通过拖动元素的右下角来扩展textarea。Selenium WebDriver调整文本区域大小

我已经试过这样的事情,但它不都

new Actions(webdriver).dragAndDropBy(element, height, width).perform() 

回答

2

更改的元素,我没有任何东西来测试这个问题,但我猜你用没了dragAndDropBy方法的原因没有用,因为它不会点击元素的右下角。我相信你会需要这样的东西:

Actions action = new Actions(driver); 
action.moveToElement(toElement, xOffset, yOffset); //moves to bottom right corner 
action.clickAndHold(); 
action.moveByOffset(xOffset, yOffset); 
action.release(); 
action.perform(); 

偏移量取决于您提到的文本区域的大小。您可以查看更多关于Action类的文章:http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/interactions/Actions.html。希望这有助于。

0

我想原因你的代码是行不通的,因为不包括build()方法是你可以试试这个,告诉如果现在working-

new Actions(webdriver).dragAndDropBy(element, height, width).build().perform(); 
0

这可以用JavaScriptExecutor界面来完成。 JavaScriptExecutor是一个接口,它提供了通过selenium webdriver执行Javascript的机制,借助于此可以更改textarea的行和列属性,因此textarea可以随其调整大小。希望这会帮助你 -

public static void main(String[] args) { 

    ProfilesIni profile = new ProfilesIni(); 
    FirefoxProfile a = profile.getProfile("default"); 
    WebDriver driver = new FirefoxDriver(a); 
    driver.get("http://localhost/testfolder/textarea.html"); 

    JavascriptExecutor js = (JavascriptExecutor) driver; 
    js.executeScript("document.getElementById('textarea').setAttribute('rows', '30')"); 
    js.executeScript("document.getElementById('textarea').setAttribute('cols', '50')"); 



} 

刚刚找到textarea元素与元素定位器然后设置“行”和“的cols”属性值。

我希望这可以帮助你。

相关问题