访问元素值

Access elements values

本文关键字:元素 访问      更新时间:2023-09-26

如何检索元素的clientWidthscrollWidth? 使用getCssValue不起作用

$('.grid-header-col .title').getCssValue('scrollWidth')

你应该改用getAttribute()

element(by.css('.grid-header-col .title')).getAttribute('scrollWidth');

scrollWidth 和 clientWidth 都是 DOM 元素的属性。因此,您需要首先通过在jquery对象之后附加[0]来获取dom元素,然后检索属性。

$('.grid-header-col .title')[0].scrollWidth
$('.grid-header-col .title')[0].clientWidth

演示