java - handle a dynamically changing element and a scroll bar -
here html code
<div class="slimscrolldiv" style="position: relative; overflow: hidden; width: auto; height: 350px;"><div class="scroller" style="height: 350px; overflow: hidden; width: auto;" data-always-visible="1" data-rail-visible1="0" data-handle-color="#d7dce2"> <div class="tsk-row clearfix"> <div class="tsk-left"> <a href="/worktask/update/776eab95-d7ea-4b5d-9c58-1c736e071895">new task check new build of 2016.4.18.1 </a> </div> <a href="/worktask/index/45d76b1d-f665-4e29-b22f-5c9cd335a957">test</a> <div class="tsk-right"> <span class="label label-warning">assigned</span> </div> </div> <div class="tsk-row clearfix"> <div class="tsk-left"> <a href="/worktask/update/e78ed656-c8d1-4623-b2f7-a70876d80a9d"> test 2</a> </div> <a href="/worktask/index/01ebc490-08d3-46f5-b9f7-139f3837e289"> test</a> <div class="tsk-right"> <span class="label label-warning">assigned</span> </div> </div> <div class="tsk-row clearfix"> <div class="tsk-left"> <a href="/worktask/update/9a992f63-f331-4e5b-a04b-b2e2bdbaa6c1"> test</a> </div> <a href="/worktask/index/01ebc490-08d3-46f5-b9f7-139f3837e289"> test</a> <div class="tsk-right"> <span class="label label-warning">assigned</span> </div> </div> <div class="tsk-row clearfix"> <div class="tsk-left"> <a href="/worktask/update/36fe32fd-f06b-47da-99d6-b3fdc060528d"> new login page</a> </div> <a href="/worktask/index/01ebc490-08d3-46f5-b9f7-139f3837e289"> test</a> <div class="tsk-right"> <span class="label label-warning">assigned</span> </div> </div> <div class="tsk-row clearfix"> <div class="tsk-left"> <a href="/worktask/update/0af36bce-755e-4744-b17b-85be5f263bf8"> new task </a> </div> <a href="/worktask/index/a7a8967d-0945-4b69-95d9-59026a1181ef">ongoing</a> <div class="tsk-right"> <span class="label label-warning">assigned</span> </div> </div> <div class="tsk-row clearfix"> <div class="tsk-left"> <a href="/worktask/update/8438470a-e19d-433b-8fa6-d6ff051db570">this testing </a> </div> <a href="/worktask/index/01ebc490-08d3-46f5-b9f7-139f3837e289"> test</a> <div class="tsk-right"> <span class="label label-warning">assigned</span> </div> </div> </div> </div><div class="slimscrollbar" style="width: 7px; position: absolute; top: 0px; opacity: 0.4; display: none; border-radius: 7px; z-index: 99; right: 0px; height: 300.245px; background: rgb(0, 0, 0);"></div><div class="slimscrollrail" style="width: 7px; height: 100%; position: absolute; top: 0px; display: none; border-radius: 7px; opacity: 0.2; z-index: 90; right: 0px; background: rgb(51, 51, 51);"></div></div>
here automation test case
public void openalltask() throws interruptedexception{
list<webelement> task=driver.findelements(by.cssselector(".tsk-row.clearfix")); // list of total no of elements present in task window system.out.println("size of loop "+task.size()); for(int i=1; i<=task.size(); i++){ //find element 1 one using xpath system.out.println(driver.findelement(by.xpath("html/body/div[2]/div[3]/div/div/div/div[3]/div/div[1]/div["+i+"]/div[1]/a")).gettext()); driver.findelement(by.xpath("html/body/div[2]/div[3]/div/div/div/div[3]/div/div[1]/div["+i+"]/div[1]/a")).click(); thread.sleep(3000); driver.navigate().back(); thread.sleep(3000); // find scroll bar , move scroll bar cirten pixles webelement element=driver.findelement(by.xpath("html/body/div[2]/div[3]/div/div/div/div[3]/div/div[2]")); actions act=new actions(driver); act.draganddropby(element, 0, (i*10)).build().perform(); thread.sleep(3000); }
i want select each element window highlighted , scroll window down when dynamically elements added can scroll down , read elements.
try below:
//i not sure css path correct or not no way check // if prints text , size correctly, fine if not please give right css path. list<webelement> elements = driver.findelements(by.cssselector(".tsk-row.clearfix > div.tsk-left> a"); system.out.println("size "+elements.size()); for(int = 0; < elements.size(); i++){ javascriptexecutor js = (javascriptexecutor)driver; webelement elem = elements.get(i); //this line scroll down make element visible js.executescript("window.scrollto(" + elem.getlocation().x + "," +(elem.getlocation().y- 100) + ");"); //don't use kind of wait, use explicit wait thread.sleep(1000); system.out.println(elem.gettext()); elem.click(); thread.sleep(3000); driver.navigate().back(); thread.sleep(3000); }
Comments
Post a Comment