How to verify presence of scrollbar in textarea using selenium.

前提是你 提交于 2020-01-06 18:05:10

问题


I have a text area in web page which has no scrollbar initially. But when i exceeds the character by 1000, scrollbar is displayed in the textarea.

I have to verify the same whether scrollbar is present or not in the textarea when i click or edit the same textarea.


回答1:


The client width or height will decrease if a scrollbar is added. So one way would be to check the size before and after.

Here's an example (Java) :

Long height_before  = Long.parseLong(element.getAttribute("clientHeight"));
element.sendKeys("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww")
Long height_after  = Long.parseLong(element.getAttribute("clientHeight"));

Assert.True((height_before - height_after) > 10);

Or:

Long clientHeight  = Long.parseLong(element.getAttribute("clientHeight"));
Long offsetHeight  = Long.parseLong(element.getAttribute("offsetHeight"));

Assert.True((offsetHeight - clientHeight) > 10);



回答2:


There are ways you can do it.

1: As mentioned that scroll bar only appears if textarea characters exceed 1000, so you can check the length of text in textarea to find whether scroll bar exists or not.

2: Get the css value for textarea and check if overflow-y is scroll. Example for python selenium

element.value_of_css_property('overflow-y')



回答3:


I had done similar verification with following way :-

 String originalScrollHt = element.getAttribute("scrollHeight");
 element.sendKeys(" 1000 words length string");
 String exceededScrollHt = element.getAttribute("scrollHeight");
 assertThat(originalScrollHt).isNotEqualToIgnoringCase(exceededScrollHt);

By taking scrollHeight as a element attribute, you will compare and verify scrollbar presence for a given element.



来源:https://stackoverflow.com/questions/40663005/how-to-verify-presence-of-scrollbar-in-textarea-using-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!