2016-01-24 43 views
1

我想模擬一個裁剪功能,我知道它不可能模擬人類裁剪,但我將裁剪的圖像是1號,我想通過在每次運行時將裁剪WebElement設置爲固定尺寸來裁剪它。測試。如何使用硒自動化種植?

要做到這一點我需要知道如何更改裁剪風格,設置其大小...所以我可以點擊裁剪按鈕來獲得裁剪能力(這很簡單),現在設置其風格如此我可以得到它的矩形。

這是風格的道具IM談到:

enter image description here

,所以我可以做這樣的事情:

val cropButton = driver.findElement(By.xpath("""//*[@id="new_company"]/input[4]""")) 
    saveButton.click() 

driver.executeScript("something to set the style") 

回答

0

您可以用在字符串替換的樣式屬性。

String newStyle = "width: 238px ..." 
JavascriptExecutor js = (JavascriptExecutor)driver; 
WebElement element = driver.findElement(By.xpath("//*[@id='new_company']/input[4]")); 
js.executeScript("arguments[0].setAttribute('style', '" + newStyle + "')", element);