getSize方法返回呈现的Web元素大小,而不是图像的物理大小。如果您的目标是获取固有的高度和重量,则可以尝试获取naturalWidth和naturalHeight属性:
WebDriver driver = new FirefoxDriver();WebDriverWait wait = new WebDriverWait(driver, 20);driver.get("http://stackoverflow.com");// get the intrinsic size with the getAttribute methodWebElement ele = driver.findElement(By.cssSelector("img"));String naturalWidth = ele.getAttribute("naturalWidth");String naturalHeight = ele.getAttribute("naturalHeight");// get the intrinsic size with a piece of JavascriptArrayList result = (ArrayList)((JavascriptExecutor) driver).executescript( "return [arguments[0].naturalWidth, arguments[0].naturalHeight];", ele);Long naturalWidth2 = (Long)result.get(0);Long naturalHeight2 = (Long)result.get(1);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)