[英]How to increase HTML table column width using webdriver
目前我正在嘗試使用Selenium webdriver自動執行增加HTML表格列寬的步驟。
我知道我可以用findElement(By.cssSelector("<Css locator>").getLocation();
獲取x和y坐標的findElement(By.cssSelector("<Css locator>").getLocation();
但我想知道是否可以使用相同的概念來增加列的寬度。
您可以使用Javascript Executor
WebDriver driver;
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.querySelector('<CSSLOCATOR>').setAttribute('width', <WIDTH>)");
在那里用你需要的東西填寫<CSSLOCATOR>
和<WIDTH>
。
回答我的問題是簡單使用jquery
$(selector).width(value);
示例用法String aScript =“jQuery(\\”“+ CSS_TABLE_HEADER_BY_COL_NAME +”\\“)。width(%s)”;
jse.executeScript(aScript );
希望這能解決大多數人在硒中增加色譜柱寬度的問題。
如果是靜態表,那么我們可以添加attirbute(不是setAttribute,因為我們需要添加新的屬性'width')'width'和該標簽。
String tableJS = "document.getElementsByTagName('table')[0].style.width='1000px'";
js.executeScript(tableJS);
注意:如果單元格或表格寬度由外部CSS處理,那么這可能不起作用。
第二種方式:如果我們有可調整表,那么我們可以找到'resizer'的元素並使用Action類在下面的解決方案中應用:
if (resizeableElement.isDisplayed()) {
Actions action = new Actions(driver);
action.clickAndHold(resizeableElement).moveByOffset(100, 100).release().build().perform();
} else {
System.out.println("Element was not displayed to drag");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.